当应用程序转到后台时,UIWebView播放音频

时间:2017-08-26 16:23:51

标签: ios swift swift3 uiwebview

我使用YouTube iOS帮助程序库在WKWebView内播放视频,我希望即使按下HOME键或锁定键,音频也会继续播放。

功能选项卡如下所示:

enter image description here

我还在import AVFoundation

中导入了AppDelegate

func applicationDidBecomeActive(_ application: UIApplication)内部我有这段代码:

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)
        }
    }

当应用程序进入后台音频停止时,我甚至无法从控制中心恢复它。

1 个答案:

答案 0 :(得分:0)

对于那些正在寻找类似解决方案的人,想告诉他们,播放YouTube音频而不显示视频违反了the terms of services of YouTube,因此您的应用将被App Store拒绝。