[IOS] Implementation of Crash collection similar to LeanCloud

Source: Internet
Author: User

[IOS] Implementation of Crash collection similar to LeanCloud

Crashlytics is used to collect Crash, which is powerful and collects various Crash data and sends emails to developers in real time.

For details, see Tang qiaoyi's article

There are many Low third-party Crash in China. After all, they are also specialized in Crash and seem to have been acquired by Twitter.

However, you have never implemented a simple Crash collection by yourself. It is simpler than a third party in China to implement basic functions?

First, let's talk about Crash. The most critical problem of the App is that users can delete the first response, and then what should they do with Crash?

NSDictionary Crash, Range beyond the Range of Crash, various Crash

First, Try Catch is implemented as follows:

@ Try {// 1 NSString * str = @ "hello world"; [str substringFromIndex: 200]; // The program crashes here} @ catch (NSException * exception) {// 2 NSLog (@ "% s \ n % @", _ FUNCTION __, exception); // @ throw exception; // no exception can be thrown here} @ finally {// 3 NSLog (@ "finally, I still execute ");} // 4 // NSLog (@ "Yeah, pass") will be executed here ");


At this time, I thought of the asserted XC implemented by Apple using Try Catch.

/*! * @define XCTAssertNil(expression, ...) * Generates a failure when ((\a expression) != nil). * @param expression An expression of id type. * @param ... An optional supplementary description of the failure. A literal NSString, optionally with string format specifiers. This parameter can be completely omitted.*/#define XCTAssertNil(expression, ...) \    _XCTPrimitiveAssertNil(self, expression, @#expression, __VA_ARGS__)#define _XCTPrimitiveAssertNil(test, expression, expressionStr, ...) \({ \    @try { \        id expressionValue = (expression); \        if (expressionValue != nil) { \            _XCTRegisterFailure(test, _XCTFailureDescription(_XCTAssertion_Nil, 0, expressionStr, expressionValue), __VA_ARGS__); \        } \    } \    @catch (_XCTestCaseInterruptionException *interruption) { [interruption raise]; } \    @catch (NSException *exception) { \        _XCTRegisterFailure(test, _XCTFailureDescription(_XCTAssertion_Nil, 1, expressionStr, [exception reason]), __VA_ARGS__); \    } \    @catch (...) { \        _XCTRegisterFailure(test, _XCTFailureDescription(_XCTAssertion_Nil, 2, expressionStr), __VA_ARGS__); \    } \})



It is a bit interesting. debugging is much more convenient, and data model processing is much more convenient, but there is always unexpected Crash.

At the same time, we also see a third-party Crash processing for basic data types and KVO. We recommend DurexKit.

Http://code4app.com/ios/DurexKit%E5% AE %89%E5%85%A8%E5%B7%A5%E5%85%B7%E5%8C%85/5325b421933bf0463d8b49ec


Back to the question: what does Crash collect in China, such as the Crash log, to give an AVOS Crash log


<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + INfUvLq/queues/ILTT08q8/rXE0MXPor + 0o6y7 + bG + expires + CjxwcmUgY2xhc3M9 "brush: java;">-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {// Override point for customization after application launch. // NSSetUncaughtExceptionHandler (& UncaughtExceptionHandler); NSString * str = @ "abc"; [str substringFromIndex: 111]; // the program will crash here and return YES ;}

Void UncaughtExceptionHandler (NSException * exception) {/*** get exception crash information */NSArray * callStack = [exception callStackSymbols]; NSString * reason = [exception reason]; NSString * name = [exception name]; NSString * content = [NSString stringWithFormat: @ "========= abnormal Error Report =========\ nname: % @ \ nreason: \ n % @ \ ncallStackSymbols: \ n % @ ", name, reason, [callStack componentsJoinedByString: @" \ n "];/*** send the exception and crash information to the developer email */NS MutableString * mailUrl = [NSMutableString string]; [mailUrl appendString: @ "mailto: tskyming@163.com"]; [mailUrl appendString :@"? Subject = program exception crash. Please send the exception report together. Thank you for your cooperation! "]; [MailUrl appendFormat: @" & body = % @ ", content]; // open the NSString * mailPath = [mailUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; [[UIApplication sharedApplication] openURL: [NSURL URLWithString: mailPath];}

The Mail content is as follows. The Crash collection function of AVOS is basically implemented, and the device model is collected, and the system adds code by itself:





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.