Ios MPRemoteCommandCenter在模拟器中工作,但不在设备上工作
编辑以解释其不重复的原因: 我正试图使用Ios MPRemoteCommandCenter在模拟器中工作,但不在设备上工作,ios,swift,Ios,Swift,编辑以解释其不重复的原因: 我正试图使用MPMusicPlayerController.systemMusicPlayer()从我的应用程序控制音乐播放,但我想禁用Command Center上一曲目按钮。我还想覆盖默认的指挥中心播放和下一曲目功能。代码应该很简单: 此代码位于ViewController.swift-viewDidLoad中 let commandCenter = MPRemoteCommandCenter.sharedCommandCenter() comma
MPMusicPlayerController.systemMusicPlayer()
从我的应用程序控制音乐播放,但我想禁用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
命令根本无法工作,如第二个屏幕截图(实际设备)所示
这与“重复”问题()的不同之处在于:
- 我使用的不是
,而是AVAudioSession
MPMusicPlayerController.systemMusicPlayer()
- 我已经调用了beginReceivingRemoteControlEvents,所以这不是问题所在(除非我不正确地调用了它,在这种情况下,我希望得到一个解释如何调用它的答案)
您的iPhone和操作系统版本是否与模拟器相同?模拟器和iPhone都有相同的操作系统。您的iPhone和操作系统版本是否与模拟器相同?模拟器和iPhone都有相同的操作系统。