IOS capture program crash log, ios capture crash log

Source: Internet
Author: User

IOS capture program crash log, ios capture crash log

It is normal to encounter a program crash during iOS development. How can I capture the exception information and notify developers when the program crashes?

The following describes how to implement it in iOS:

1. Add an exception capture listener when the program starts to handle the callback action when the program crashes.

NSSetUncaughtExceptionHandler (& UncaughtExceptionHandler );

Official documentation: Sets the top-level error-handling function where you can perform last-minute logging before the program terminates.
UncaughtExceptionHandler is a function pointer, which needs to be implemented and can be named as needed. When a program crashes abnormally, the function is called, which is the same as the callback function in C and C ++.

2. Implement your own processing functions

Void UncaughtExceptionHandler (NSException * exception) {NSArray * arr = [exception callStackSymbols]; // obtain the current call stack information NSString * reason = [exception reason]; // very important, is the cause of the crash NSString * name = [exception name]; // exception type NSLog (@ "exception type: % @ \ n crash reason: % @ \ n call stack info: % @ ", name, reason, arr );}

The above code is very simple, but the function is very big.

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.