当我的应用程序因内存不足、内存泄漏等一般崩溃而崩溃时退出时,我想与我的服务器进行一些交互。我想知道,在这种情况下是否会调用任何委托方法,以便我可以在应用程序因任何崩溃而退出之前快速联系我的服务器。
谢谢。
正如您所解释的,您需要联系服务器,您可以在应用程序因任何崩溃而退出之前立即联系您的服务器。
在这种情况下你应该设置exception handler
as any exception
将会发生,您会收到通知
看看你怎么能做到这一点
写这个NSSetUncaughtExceptionHandler (&uncaughtExceptionHandler)
中的代码行applicationDidFixnishLaunchin
的方法Appdelegate
Class
-(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"];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)