3

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.")
    }
}

回線を修正MPNowPlayingInfoCenterしてもロック画面に何も表示されません。私が間違っていることは何ですか?

コードはチュートリアルから

4

1 に答える 1

4

わかりました、私はそれを修正しました。問題は AVAudioSession の部分にありました:

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)

そして、リモコンは機能しています:)

于 2015-11-27T23:46:48.610 に答える