IOS capture program crash log

Source: Internet
Author: User

IOS capture program crash log

We often encounter a crash when running an APP on an iPhone or iPad tablet. Sometimes an APP is turned on, but it suddenly crashes. This is definitely a headache for developers. So how can I get the iOS device crash log? This provides some simple methods for developers to communicate with users.

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.

The Code is as follows:

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

The Code is as follows:

Void UncaughtExceptionHandler (NSException * exception ){

NSArray * arr = [exception callStackSymbols]; // obtain the current call stack information

NSString * reason = [exception reason]; // the cause of the crash is very important.

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.

The above is all the content of this article. I hope it will be helpful for you to learn about IOS development.

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.