swift 4 中的 MPRemoteCommandCenter 错误
MPRemoteCommandCenter Error in swift 4
我正在尝试设置我的应用程序以使用 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
}
}
你需要import MediaPlayer
我正在尝试设置我的应用程序以使用 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
}
}
你需要import MediaPlayer