我关注了这篇文章:SKAction playSoundFileNamed stops background music它的工作原理是当SK声音动作运行时,音乐不再暂停。
不幸的是,当应用程序最初启动时,音乐仍然停止。我也尝试过其他帖子(background device music gets stopped as app starts ios)的代码,但要么不起作用。
如何阻止我的应用在初次发布时暂停音乐?也许我没有将我的代码放在正确的位置?
代码:
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(AVAudioSessionCategoryAmbient)
} catch _ {
}
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch _ {
}
}
谢谢!
编辑1(用于评论)
{{1}}