IPhone development capture and submit exception logs

Source: Internet
Author: User

In recent months, at the company's arrangement and my personal requirements, I have been involved in iPhone development, mainly in the application field. I participated in the development of two iPhone projects, it has been compared to the AppStore, so you can finally take a rest for a while.
A problem often occurs during project development. Every time a hard version is released to the tester for testing, we get bugs. In the face of these problems, some problems are still easy to find, and those problems that are hard to reproduce are left speechless. If it is not on a simulator or our device is not connected to a PC, how can we debug our program? If the app cannot be sent to the AppStore, the user may encounter a problem during use. We certainly hope to be able to perceive the problem and modify and improve our app when updating the next version.
This leads to a requirement: capture exceptions during application use and submit them to the server or developer's mailbox.
Let's talk about the code.
1. It is used to handle exceptions not captured by try... catch...
Void UncaughtExceptionHandler (NSException * exception ){
// Abnormal stack information
NSArray * stackArray = [exception callStackSymbols];
// Cause of exception
NSString * reason = [exception reason];
// Exception name
NSString * name = [exception name];

NSString * syserror = [NSString stringWithFormat: @ "Exception name: % @ \ n cause of exception: % @ \ n exception stack information: % @", name, reason, stackArray];
NSLog (@ "% @", syserror );

// Send an exception to the developer's email address or send it to the server
}
2. Replace the original Handler that handles exceptions in the application startup.
// Save the Handler for handling system exceptions
_ UncaughtExceptionHandler = NSGetUncaughtExceptionHandler ();
// Set the Handler to handle exceptions
NSSetUncaughtExceptionHandler (& UncaughtExceptionHandler );
3. Restore the Handler for exception handling when the application exits.
-(Void) applicationWillTerminate :( UIApplication *) application
{
// Restore to the Handler for system Exception Handling
NSSetUncaughtExceptionHandler (_ uncaughtExceptionHandler );
}
In this way, if the tester or user finds the collapse problem, we can easily find the cause and correct it.
If you think there are any shortcomings in this strategy, leave a message to discuss it.

 

From ahutzh
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.