applicationWillTerminate 未调用
我实现了 applicationWillTerminate 方法,但从未调用它
-(void)applicationWillTerminate:(NSNotification *)notification
{
[[NSApplication sharedApplication] terminate:self];
NSLog(@"EOP");
}
如何在应用程序关闭之前执行一些代码?
谢谢
I implemented applicationWillTerminate method, but it's never called
-(void)applicationWillTerminate:(NSNotification *)notification
{
[[NSApplication sharedApplication] terminate:self];
NSLog(@"EOP");
}
How to execute some code before application close?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚添加了
Now applicationWillTerminate 调用
I just added
Now applicationWillTerminate invokes
解决方案 1:
在项目信息(
NSSupportsSuddenTermination
键)中将应用程序可以立即终止设置为NO。然后,在应用程序退出之前,将调用
applicationWillTerminate
函数。解决方案 2:
如果您需要能够取消终止,那么您应该重写
applicationShouldTerminate
函数Solution 1:
Set the Application can be killed immediately to NO in the project info (
NSSupportsSuddenTermination
key ).The
applicationWillTerminate
function will then be called before the application quits.Solution 2:
If you need to be able to cancel the termination, then you should rather override the
applicationShouldTerminate
function请将您的 plist 中的键 (
UIApplicationExitsOnSuspend
) 设置为YES
。please set a key (
UIApplicationExitsOnSuspend
) in your plist toYES
.