Capture the abnormal exit information in the ios program and submit it to the server

Source: Internet
Author: User

You can write a class crashpolictioincatcher and define a static method startCrashExceptionCatch in the class. In the method, call NSSetUncaughtExceptionHandler (& uncaughtExceptionHandler );

Bind the void uncaughtExceptionHandler (NSException * exception) method to handle exception information. Print the exception in void uncaughtExceptionHandler (NSException * exception) and submit the device information to the server, in this way, exception information can be effectively collected during testing.

Header file

#import 
 
  @interface CrashExceptioinCatcher : NSObject+ (void)startCrashExceptionCatch;@end
 

Implementation File

# Import "crashpolictioincatcher. h "// submit the exception Log information void uncaughtExceptionHandler (NSException * exception) {// The exception Log information NSString * logInfo = [NSString stringWithFormat: @" Crash: \ n % @ \ nStack Trace: \ n % @ \ n ", [exception description], [exception callStackSymbols]; NSLog (@" % @ ", logInfo ); // TODO: Submit to the server for collection //....} @ implementation CrashExceptioinCatcher + (void) startCrashExceptionCatch {// Sets the top-level error-handling function where you can perform last-minute logging before the program terminates. NSSetUncaughtExceptionHandler (& uncaughtExceptionHandler); // sets the exception Log information processing} @ end

Usage:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{        [CrashExceptioinCatcher startCrashExceptionCatch];        // .................    }



Reference: http://arthurchen.blog.51cto.com/2483760/734175

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.