5

Since I updated to ios 12.2 lockscreen controls stopped to work for me and I can't figure out why. It worked fine in ios 12.1

  1. App has enabled capabilities->Background mores -> Audio
  2. I set UIApplication.shared.beginReceivingRemoteControlEvents()
  3. Then I set

    MPRemoteCommandCenter.shared().playCommand.isEnabled = true                   
    MPRemoteCommandCenter.shared().pauseCommand.isEnabled = true
    MPRemoteCommandCenter.shared().playCommand.addTarget(self, action:#selector(self.playPlayer))
    MPRemoteCommandCenter.shared().pauseCommand.addTarget(self, action: #selector(self.pausePlayer))
    
  4. Then AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback) and AVAudioSession.sharedInstance().setActive(true)

I use AVPlayer and AVPlayer item. Locksceen controls never show up on ios 12.2. Any idea what can be causing this issue? Thanks

(I use xcode 10.2 and swift 4.2)

EDIT: I was able to figure out that this happens only when device is online. If I play immediately, lockscreen controls will show up and then disappear in few seconds. If I play later, they will not show up. So it seems they work few seconds after app start and then don't

EDIT 2: Fixed now. Issue was caused by app loading local html file into webview. Completely unrelated to playback but that's it. Solution is not to load webview

Martin Vandzura
  • 3,047
  • 1
  • 31
  • 63
  • What does "when device is online" mean? – matt Apr 17 '19 at 17:25
  • @matt with access to internet (wifi is on) – Martin Vandzura Apr 17 '19 at 17:28
  • Why would that make a difference? Are you playing some kind of streaming audio? – matt Apr 17 '19 at 17:41
  • @matt I tried local and remote files. I figured out what it was. It was happening because in another part of app I load html file into webview! I have no idea why but that was problem – Martin Vandzura Apr 17 '19 at 17:53
  • OK, that's really interesting! The html file you are loading in the web view may have an audio component, and this takes over as the remote target (or something). Anyway, this could be totally useful to others, so please, instead of answering your own question in the question, add the answer as an _answer_ (yes this is legal and encouraged, and in 48 hours you can even accept your own answer). And congratulations on your great detective work. – matt Apr 17 '19 at 18:07

2 Answers2

4

Issue was caused by app loading local html file into UIWebView. Completely unrelated to playback but that's it. Solution is not to load UIWebView but use WKWebView instead.

Similar issue was discussed here but I found it only because I know already what was causing it.

Martin Vandzura
  • 3,047
  • 1
  • 31
  • 63
1

I agree with vandzi's answer. We investigated it further and figured out in our case it was the use of UIWebView in Google Mobile Ads framework for showing Ads. Whenever the Ads HTML content has some audio component associated with it, the Audio session loses focus. P.S. This was happening only on iOS 12.2 and above, as stated above. (we verified this in the same test environment for different iOS versions.)

Update: Now Apple has started sending warning messages for deprecated use of UIWebView while deploying the App to app store.

MESSAGE: " ITMS-90809: Deprecated API Usage - Apple will stop accepting submissions of apps that use UIWebView APIs". Link: https://forums.developer.apple.com/thread/122114

Sharing this as some of us might not be using UIWebview directly and via some third party.

Nick
  • 138,499
  • 22
  • 57
  • 95