我正在尝试将我的应用程序设置为使用 MPRemoteCommandCenter。我从文档编程指南中得到了这个例子。我导入了 AVFoundation,甚至尝试导入 AVKIT,我收到错误Use of unresolved identifier 'MPRemoteCommandCenter'。当我创建 MPRemoteCommandCenter.shared() 的实例时。任何帮助,将不胜感激。
func setupRemoteTransportControls() {
// Get the shared MPRemoteCommandCenter
let commandCenter = MPRemoteCommandCenter.shared() Error //**Use of unresolved identifier 'MPRemoteCommandCenter'**
// Add handler for Play Command
commandCenter.playCommand.addTarget { [unowned self] event in
if self.audioPlayer.rate == 0.0 {
self.audioPlayer.play()
return .success
}
return .commandFailed
}
// Add handler for Pause Command
commandCenter.pauseCommand.addTarget { [unowned self] event in
if self.audioPlayer.rate == 1.0 {
self.audioPlayer.pause()
return .success
}
return .commandFailed
}
}