Xcode Swift 2.0中的遥控器(MPNowPlayingFoCenter)

Xcode Swift 2.0中的遥控器(MPNowPlayingFoCenter),xcode,lockscreen,remote-control,mpnowplayinginfocenter,Xcode,Lockscreen,Remote Control,Mpnowplayinginfocenter,我正在尝试用Swift制作一个广播应用程序。锁屏上的遥控器也有问题。根本不起作用——屏幕上什么都没有。来自ViewController的代码: override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. playButton.setTitle("Play", forState: UICo

我正在尝试用Swift制作一个广播应用程序。锁屏上的遥控器也有问题。根本不起作用——屏幕上什么都没有。来自ViewController的代码:

 override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    playButton.setTitle("Play", forState: UIControlState.Normal)
    if NSClassFromString("MPNowPlayingInfoCenter") != nil {
        let image:UIImage = UIImage(named: "logo_player_background")!
        let albumArt = MPMediaItemArtwork(image: image)
        var songInfo: NSMutableDictionary = [
            MPMediaItemPropertyTitle: "Radio Brasov",
            MPMediaItemPropertyArtist: "87,8fm",
            MPMediaItemPropertyArtwork: albumArt
        ]
        MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = songInfo as [NSObject : AnyObject]
    }
    if (AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)) {
        println("Receiving remote control events")
        UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
    } else {
        println("Audio Session error.")
    }
}
即使在修复
mpnowPlayingFoCenter
行后,锁定屏幕上也不会显示任何内容。我做错了什么


代码来自

好的,我已经修好了。问题在于部分音频会话:

if (AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)) {
    println("Receiving remote control events")
    UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
} else {
    println("Audio Session error.")
我已将其替换为:

try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: [])
    try! AVAudioSession.sharedInstance().setActive(true)

遥控器也在工作:)

你刚刚让我的一天+1