#import <Foundation/Foundation.h>@interface zruncaughtexceptionhandler:nsobject + (void) Setdefaulthandler; + (nsuncaughtexceptionhandler*) gethandler; @end
#import "ZRUncaughtExceptionHandler.h"@implementationzruncaughtexceptionhandlernsstring*applicationdocumentsdirectory () {return[Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) lastobject];}voidUncaughtexceptionhandler (NSException *exception) {Nsarray*arr =[Exception callstacksymbols]; NSString*reason =[Exception reason]; NSString*name =[exception name]; NSString*url = [NSString stringWithFormat:@"============= exception crash report =============\nname:\n%@\nreason:\n%@\ncallstacksymbols:\n%@", Name,reason,[arr componentsjoinedbystring:@"\ n"]]; NSString*path = [Applicationdocumentsdirectory () stringByAppendingPathComponent:@"Exception.txt"]; [url Writetofile:path atomically:yes encoding:nsutf8stringencoding error:nil];}-(NSString *) Applicationdocumentsdirectory {return[Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) lastobject];}+ (void) setdefaulthandler{Nssetuncaughtexceptionhandler (&uncaughtexceptionhandler);}+ (nsuncaughtexceptionhandler*) gethandler{returnNsgetuncaughtexceptionhandler ();}@end
Use the following
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions { [Zruncaughtexceptionhandler Setdefaulthandler]; return YES;}
IOS Crash Log