# Import "nduncaughtexceptionhandler. H" Nsstring * applicationdocumentsdirectory (){ Return [nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes) lastobject]; } Void uncaughtexceptionhandler (nsexception * exception ){ Nsarray * arr = [Exception callstacksymbols]; Nsstring * Reason = [Exception reason]; Nsstring * name = [Exception name]; Nsstring * url = [nsstring stringwithformat: @ "=============== abnormal 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: nsutf8stringencodingerror: Nil]; // In addition to writing to a file under the application, the information can be sent to the server through subsequent processing. // You can also call the email sending program to send information to the specified email address. // Or call a handler to process this information } @ Implementation nduncaughtexceptionhandler -(Nsstring *) applicationdocumentsdirectory { Return [nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes) lastobject]; } + (Void) setdefaulthandler { Nssetuncaughtexceptionhandler (& uncaughtexceptionhandler ); } + (Nsuncaughtexceptionhandler *) gethandler { Return nsgetuncaughtexceptionhandler (); } @ End |