قالب وردپرس درنا توس
Home / IOS Development / ios – Music information displayed in Command Center but not Lock screen

ios – Music information displayed in Command Center but not Lock screen



Using Swift 4+, iOS 11+, Xcode 10+

I've built a music player using MPMediaPlayer, and I can communicate with it from the Command Center, but I will also be able to see it on the Lock screen.

To be honest, I'm a little confused as to why it is showing / working in the Command Center, since I haven't written any code to do so.
Still, I would also like to show it in the Lock screen.

This is what I have done so far:

1) I use the program MusicPlayer and made sure something is playing during my tests:

  MPMusicPlayerController.applicationMusicPlayer

2) Set the background modes to include audio, download and remote alerts

 enter picture description here

3) Added AVAudioSession code (which doesn't seem to do anything have tried it and tried to comment on it and seen no difference):

  la session = AVAudioSession.sharedInstance ()
do {
// Configure the audio session for playback
try session.setCategory (AVAudioSessionCategoryPlayback,
mode: AVAudioSessionModeDefault,
alternatives: [])
try session.setActive (true)
} capture errors like NSError {
print ("Could not specify the audio session category and mode:  t
}

4) Used this basic code to see if I can make it appear on the lock screen with just some basic hard-coded content:

  la nowPlayingInfo: [String: Any] = [
    MPMediaItemPropertyArtist: "Pink Floyd",
    MPMediaItemPropertyTitle: "Wish You Were Here",
    //MPMediaItemPropertyArtwork: mediaArtwork,
]
MPNowPlayingInfoCenter.default (). NowPlayingInfo = nowPlayingInfo

UIApplication.shared.beginReceivingRemoteControlEvents ()
la commandCenter = MPRemoteCommandCenter.shared ()

5) I know I haven't implemented anything to actively update the information or respond to commands, as I'm just trying to get something to show on the lock screen at this time.

Why is the playback information in the command center if I haven't done anything to say it there?

What do I have to do to get the information displayed on the lock screen as it does in the command center?

EDIT:
Link to single project that has the same problem on GitLab: https: //gitlab.com/whoit/lockscreentest

EDIT: I sent this as a bug to Apple, but they have not yet verified or solved this.


Source link