Ios 为WKWebview设置音频会话类别

Ios 为WKWebview设置音频会话类别,ios,swift,wkwebview,Ios,Swift,Wkwebview,我有一个WKWebView在那里我显示我的网站。我用js播放音效,但当我这样做时背景音乐停止播放。我喜欢将这种音效与Spotify等背景音乐混合 你知道我是怎么做到的吗 这是我在ViewController.swift中的代码 导入WebKit 进口AVF基金会 类ViewController:UIViewController、WKNavigationDelegate{ var-webView:WKWebView! 重写func loadView(){ webView=WKWebView()

我有一个WKWebView在那里我显示我的网站。我用js播放音效,但当我这样做时背景音乐停止播放。我喜欢将这种音效与Spotify等背景音乐混合

你知道我是怎么做到的吗

这是我在ViewController.swift中的代码

导入WebKit
进口AVF基金会
类ViewController:UIViewController、WKNavigationDelegate{
var-webView:WKWebView!
重写func loadView(){
webView=WKWebView()
webView.navigationDelegate=self
//设置为播放内联作品
让webConfiguration=WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback=true
如果可用(iOS 10.0,*){
webConfiguration.mediaTypesRequiringUserActionForPlayback=[]
}否则{
//对早期版本的回退
webConfiguration.MediaPlaybackRequiresAction=false
}
webView=WKWebView(帧:CGRect.zero,配置:webConfiguration)
//super.init(编码者:aDecoder)
视图=网络视图
}
重写func viewDidLoad(){
super.viewDidLoad()
//加载视图后,通常从nib执行任何其他设置。
//设置为可以在不停止背景音乐的情况下播放音效
//从iphone获取本地语言
var locale=locale.preferredLanguages[0]
if(locale.contains(“-”){
locale=locale.substring(to:locale.characters.index(locale.startIndex,offsetBy:2))
}
让url=url(字符串:https://test.com/?lang=“+locale)!
加载(url请求(url:url))
webView.AllowsBackforwardNavigationPigests=true
//将背景色添加到wkwebview至透明
webView.backgroundColor=UIColor.clear
webView.scrollView.backgroundColor=UIColor.clear
//将状态栏更改为vit
UIApplication.shared.statusBarStyle=.lightContent
}
重写函数didReceiveMemoryWarning(){
超级。我收到了记忆警告()
//处置所有可以重新创建的资源。
}

}
我发现这是不可能的