title: iOS 12 Lock screen controls for music app
body: <p>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...</p>
  
  <p>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.</p>
  
  <p>Here is what I have</p>
  
  <p>In the Background Modes</p>
  
  <p><a href="https://i.stack.imgur.com/uLCbS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/uLCbS.png" alt="Modes"></a></p>
  
  <p>I have updated my code to the following:</p>
  
  <p>Called in my <code>viewDidLoad</code></p>
  
  <pre><code>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()
  </code></pre>
  
  <p>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</p>
  
  <pre><code>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")]
  }
  </code></pre>
  
  <p>I put breakpoints on the <code>do try</code> it does not print either of the print functions and skips the <code>try</code></p>
  
  <p>Did I convert my code wrong?</p>