Swift 2.3,SpriteKit
我了解AppDelegate功能:
applicationWillResignActive
和applicationDidEnterBackground
我有以下代码:
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
mainScene.view?.paused = true
}
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
}
使用applicationDidEnterBackground
它可以正常工作。我可以通过点击Home Button暂停场景并在之后恢复。
但是使用applicationWillResignActive
它不起作用。当我运行游戏并接听电话时,游戏不会暂停。它一直在后台运行,所以当我完成呼叫并返回时,我可以看到我的所有节点完全混乱。
我使用print
语句检查applicationWillResignActive
是否在我接到电话时工作,它显示它正在执行,但应用程序只是暂停。
此外,我注意到,当我点按主页按钮时,应用会调用applicationWillResignActive
,然后调用applicationDidEnterBackground
个功能。当我接到电话时,只调用applicationWillResignActive
功能。
所以我的问题是 - 如何通过applicationWillResignActive
功能处理电话和暂停我的应用程序。我不明白为什么我可以在点击Home Button时暂停它,而当我接到电话时却无法暂停。