applicationWillTerminate:未被调用
我正在使用 applicationWillTerminate:
来保存一些最后一刻的内容。但问题是它永远不会被调用。如果我在方法顶部执行类似的操作: NSLog(@"Something");
它不会被调用,也不会输出到控制台。
有谁知道为什么会发生这种情况?
I'm using applicationWillTerminate:
to save some last-minute stuff. But the problem is that it never gets called. If I do something like this at the top of the method: NSLog(@"Something");
it doesn't get called and doesn't get outputted to the console.
Does anyone know why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自 Apple 文档:
对于不支持后台执行或链接到 iOS 3.x 或更早版本的应用程序,当用户退出应用程序时始终会调用此方法。 对于支持后台执行的应用程序,当用户退出应用程序时,通常不会调用此方法,因为在这种情况下应用程序只是移至后台。但是,当应用程序在后台运行(未挂起)并且系统由于某种原因需要终止它的情况下,可能会调用此方法。
如果您的应用启用了后台功能,请使用:
- (void)applicationDidEnterBackground:(UIApplication *)application
From Apple docs:
For applications that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the application. For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason.
If your app has background enabled use:
- (void)applicationDidEnterBackground:(UIApplication *)application
请改用
applicationDidEnterBackground:
。当您在多任务系统中按下主页按钮时,应用程序不会终止。Use
applicationDidEnterBackground:
instead. Applications aren't terminated when you press the home button in a multitasking system.来自 iOS 应用程序编程指南关于核心应用程序设计和应用程序生命周期:
如果您要链接到 iOS 4.0,您还应该将数据保存在
applicationDidEnterBackground:
中。From the iOS Application Programming Guide on Core Application Design and Application life time:
If you are linking against iOS 4.0, you should also save data in
applicationDidEnterBackground:
.第 1 步:command + shift + h(双击(tab))
第 2 步:移动应用程序顶部(kill)
第 3 步:applicationWillTerminate Work
step 1: command + shift + h (double click(tab))
step 2: move app top side (kill)
step 3: applicationWillTerminate Work