编辑解释为什么它不重复:
我正在尝试使用MPMusicPlayerController.systemMusicPlayer()
来控制我应用中的音乐播放,但我想禁用Command Center上一曲目按钮。我还想覆盖默认的Command Center播放和下一个音轨功能。代码应该很简单:
此代码位于ViewController.swift - viewDidLoad
中 let commandCenter = MPRemoteCommandCenter.sharedCommandCenter()
commandCenter.previousTrackCommand.enabled = false
commandCenter.previousTrackCommand.addTargetWithHandler({ (commandEvent: MPRemoteCommandEvent!) -> MPRemoteCommandHandlerStatus in
self.empty()
return MPRemoteCommandHandlerStatus.Success
})
//MPRemoteCommandCenter.sharedCommandCenter().previousTrackCommand.addTarget(self, action: "empty")
commandCenter.nextTrackCommand.enabled = true
commandCenter.nextTrackCommand.addTargetWithHandler { (commandEvent: MPRemoteCommandEvent!) -> MPRemoteCommandHandlerStatus in
self.gameOver()
return MPRemoteCommandHandlerStatus.Success
}
commandCenter.playCommand.enabled = true
commandCenter.playCommand.addTargetWithHandler { (commandEvent: MPRemoteCommandEvent!) -> MPRemoteCommandHandlerStatus in
self.playing()
return MPRemoteCommandHandlerStatus.Success
}
另外,在AppDelegate.swift中 - 应用程序
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
在iOS模拟器(iPad和iPhone)中,它可以正常工作,如第一个屏幕截图(模拟器)中所示。
但是,在将应用程序部署到我的iPad时,MPRemoteCommandCenter
命令都不起作用,如第二个屏幕截图(实际设备)中所示。
这与“重复”问题(How Do I Get Audio Controls on Lock Screen/Control Center from AVAudioPlayer in Swift)在以下方面有所不同:
AVAudioSession
,我正在使用MPMusicPlayerController.systemMusicPlayer()
beginReceivingRemoteControlEvents
,因此无法解决问题(除非我以某种方式错误地调用它,在这种情况下,我希望得到一个答案,解释应该如何调用它)。谢谢。
,