xcode - MPNowPlayingInfoCenter info is not displayed on iOS 8

后端 未结 4 1447
别那么骄傲
别那么骄傲 2020-12-05 12:19

I\'m developing a music application, which should play music in the background.

I use the MPMoviePlayerController to play the music. My code to initiate

相关标签:
4条回答
  • 2020-12-05 12:58

    The problem is that you are not satisfying the requirements to become master of the lock screen and control center, as I explain in my book. You should be seeing the modern (iOS 8) equivalent of this:

    enter image description here

    The fact that you are not seeing it suggests that you are omitting one or more of the requirements, which I list (quoting directly from my book here):

    • Your app must contain a UIResponder in its responder chain that returns YES from canBecomeFirstResponder, and that responder must actually be first responder.
    • Some UIResponder in the responder chain, at or above the first responder, must implement remoteControlReceivedWithEvent:.
    • Your app must call the UIApplication instance method beginReceivingRemoteControlEvents.
    • Your app’s audio session’s policy must be Playback.
    • Your app must be emitting some sound.

    I don't know which of those you are omitting; it could be more than one. You might like to compare your code with a working example, here:

    https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/iOS7bookExamples/bk2ch14p653backgroundPlayerAndInterrupter/backgroundPlayer/backgroundPlayer/ViewController.m

    0 讨论(0)
  • 2020-12-05 12:59

    Expanding further on @matt's answer, it's required that you call endReceivingRemoteControlEvents and resignFirstResponder when the app comes back into the foreground (applicationDidBecomeActive). Otherwise the OS assumes you are a bad actor (or forgot to turn them off) and turns off your ability to show the sleep controls entirely, even after you call beginReceivingRemoteControlEvents again. I added these calls and now the Sleep Controls always show when they should.

    0 讨论(0)
  • 2020-12-05 13:16

    Want to expand @matt's answer - setting nowPlayingInfo is useless when you use AVAudioSessionCategoryOptionMixWithOthers option.

    0 讨论(0)
  • 2020-12-05 13:16

    Want to explain @zakhej's answer - what's happens when set AVAudioSessionCategoryOptionMixWithOthers.

    1. MPNowPlayingInfoCenter is a singleton, which means can only one application set it.
    2. AVAudioSession is shared with other apps, every app can set it.

    so. when you set category AVAudioSessionCategoryAmbient, AVAudioSessionCategoryPlayAndRecord and mix with others, AVAudioSessionCategoryPlayback and mix with others, setting MPNowPlayingInfoCenter's nowPlayingInfo is useless.

    0 讨论(0)
提交回复
热议问题