iOS catches exceptions and sends pictures for easy resolution of bugs

Source: Internet
Author: User
Tags stack trace

In the development process, we sometimes leave a bug, users in the use of our app, sometimes there will be a flashback, this time we can let users send us email, so that our developers more high-speed status to the location of the bug. Solve the problem in the quickest time. Also improve the user experience at the same time.

in the APPDELEGATE.M file, add code such as the following:

01 NSUncaughtExceptionHandler* _uncaughtExceptionHandler = nil;
02 voidUncaughtExceptionHandler(NSException *exception) {
03     NSLog(@"CRASH: %@", exception);
04     NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
05     
06     // 异常的堆栈信息
07     NSArray *stackArray = [exception callStackSymbols];
08     // 出现异常的原因
09     NSString *reason = [exception reason];
10     // 异常名称
11     NSString *name = [exception name];
12     
13     NSString *syserror = [NSString stringWithFormat:@"mailto://[email protected]?subject=bug报告&body=感谢您的配合!<br><br><br>"
14                           "Error Detail:<br>%@<br>--------------------------<br>%@<br>---------------------<br>%@",
15                           name,reason,[stackArray componentsJoinedByString:@"<br>"]];
16     
17     NSURL *url = [NSURL URLWithString:[syserror stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
18     [[UIApplication sharedApplication] openURL:url];
19     return;
20 }
And then in- ( BOOL ) Application: ( uiapplication *) Application didfinishlaunchingwithoptions: (nsdictionary *) Add code to the Launchoptions method:

1 // 保存系统处理异常的Handler
2     _uncaughtExceptionHandler = NSGetUncaughtExceptionHandler();
3     
4     // 设置处理异常的Handler
5     NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);

iOS catches exceptions and sends pictures for easy resolution of bugs

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.