当我点按主页按钮时,应用会在我回复后调用AppDelegate
功能applicationDidEnterBackground
和applicationWillEnterForeground
。
我使用以下代码:
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
mainScene.view?.paused = true
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
mainScene.view?.paused = false
}
它工作正常。我可以暂停应用并在需要时恢复它。但是,如果我在我的应用程序中使用{{1}播放声音(例如"枪火"或"硬币掉落"等等)时点按主页按钮然后尝试恢复应用程序,它崩溃了。我可以正常恢复它的唯一方法就是当我点击Home Button时没有任何有效声音。
任何解决方法?