gpt4 book ai didi

iOS:当应用程序因任何崩溃而退出时是否有任何委托(delegate)方法

转载 作者:可可西里 更新时间:2023-11-01 03:42:01 24 4
gpt4 key购买 nike

当我的应用程序因内存不足、内存泄漏等一般崩溃而在崩溃时退出时,我想与我的服务器进行一些交互。我想知道,在这种情况下是否会调用任何委托(delegate)方法,以便我可以在应用程序因任何崩溃而退出之前立即快速联系我的服务器。

谢谢。

最佳答案

正如您所解释的,您需要通知服务器,您可以在应用程序因任何崩溃而退出之前立即联系您的服务器。

在那种情况下你应该设置exception handler因为任何exception都会发生你会得到通知

看看你是怎么做到的

将这NSSetUncaughtExceptionHandler (&uncaughtExceptionHandler)行代码写在Appdelegate类的applicationDidFixnishLaunchin方法中

 -(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:  
(NSDictionary*)launchOptions
{
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

EDIT:
if( [[NSUserDefaults standardUserDefaults] boolForKey:@"isExceptionOccured"])
{
//call sever code here
[[NSUserDefaults standardUserDefaults] setBool:FALSE forKey:@"isExceptionOccured"];
}
//rest of your code
}


void uncaughtExceptionHandler(NSException *exception)
{


NSLog(@"Exception Got %@",[exception description]);
//do what ever you what here
//can save any `bool` so that as aaplication run on immediate next launching of crash
//could intimate any thing

EDIT:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isExceptionOccured"];

}

关于iOS:当应用程序因任何崩溃而退出时是否有任何委托(delegate)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16330411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com