In iOS 11 my music app would show the lock screen controls when I locked my iPhone. I was able to see the currently playing song and play/pause skip forward and backwards. However in upgrading to Xcode 10/iOS 12 I can no longer see the lock screen controls just the date and time...
However, if I swipe up and get that widget screen (where you can turn on airplane mode etc) I CAN see the now playing info.
Here is what I have
In the Background Modes
I have updated my code to the following:
Called in my viewDidLoad
do {
try AVAudioSession.sharedInstance().setCategory(.soloAmbient, mode: .default, options: .allowAirPlay)
print("Playback OK")
try AVAudioSession.sharedInstance().setActive(true)
print("Session is Active")
} catch {
print(error)
}
UIApplication.shared.beginReceivingRemoteControlEvents()
self.becomeFirstResponder()
I did not previously have the following code in the last working version but I added it because I found similar posts suggesting I do it
if let songInfo = self.mediaPlayer.nowPlayingItem {
nowPlayingInfoCenter.nowPlayingInfo = [
MPMediaItemPropertyTitle: songInfo.title ?? "",
MPMediaItemPropertyArtist: songInfo.artist ?? "",
MPMediaItemPropertyArtwork : songInfo.artwork?.image(at: CGSize(width: 400, height: 400)) ?? #imageLiteral(resourceName: "emptyArtworkImage")]
}
I put breakpoints on the do try
it does not print either of the print functions and skips the try
Did I convert my code wrong?
from iOS 12 Lock screen controls for music app
No comments:
Post a Comment