I'm using YouTube iOS Helper Library to play a video inside a WKWebView
and I want the audio to continue playing even when HOME is pressed or lock key.
Capabilities tab looks like this:
I have also imported import AVFoundation
inside AppDelegate
and inside func applicationDidBecomeActive(_ application: UIApplication)
I have this code:
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch {
// Handle setCategory failure
print(error)
}
}
When app enters background audio stops and I can not even resume it from control center.