我正在尝试处理电话和待机以及那种性质的事情。我添加了函数
- (void)applicationWillResignActive:(UIApplication *)application
和
- (void)applicationDidBecomeActive:(UIApplication *)application
到我的UIApplicationDelegate。当退出待机状态时,“applicationDidBecomeActive”总是被调用。但问题是“applicationWillResignActive”永远不会被调用。
我想知道是否有人遇到过这个问题以及是否有人找到了理由。
修改
更多信息,我发现我的引擎更新循环从applicationDidFinishLaunching运行导致我错过了该消息。我打电话给
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, .002, FALSE) == kCFRunLoopRunHandledSource);
捕获所有iphone消息,但在变为非活动状态之前似乎没有捕获resignActive消息。
尝试为我的更新循环分叉线程会导致奇怪的崩溃错误。有人有任何快速修复建议吗?
答案 0 :(得分:6)
当主页按钮被点击时,它会在iOS 4.0中被调用。
在iOS 4.0中点击主页按钮时会调用以下委托方法
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"Application Did Resign Active");
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(@"Application Did Enter Background");
}
当您双击主页按钮并再次重新启动应用程序时,将调用以下委托方法。
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"Application Will Enter Foreground");
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(@"Application Did Become Active");
}
答案 1 :(得分:2)
我不认为
- (void)applicationWillResignActive:(UIApplication *)application
收到电话时会调用。我认为操作系统会等待用户接听或拒绝接听电话。如果我拒绝了,那么该应用程序会活着并且
- (void)applicationDidBecomeActive:(UIApplication *)application
被调用。如果有人接听,则告知您的应用退出并接收
- (void)applicationWillTerminate:(UIApplication *)application
答案 2 :(得分:0)
一定要允许
- (void)applicationDidFinishLaunching:(UIApplication *)application
在运行游戏循环之前返回。一种技术是使用函数
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
在应用程序委托上并在延迟说“.01”之后运行游戏循环执行此操作后,该消息应该能够正常启动。我认为消息踩踏的原因是因为运行循环停留在applicationDidFinishLaunching上,并且无法将任何其他UIApplicationDelegate消息推送到队列中。
答案 3 :(得分:-2)
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active state 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.
*/
}