IOS Capture program crash log _ios

Source: Internet
Author: User

It is normal to encounter a program crash in iOS development, how to catch exception information when a program crashes and notify the developer?

Here's how to implement this in iOS:

1. Add an exception capture listener at the start of the program to handle the callback action when the program crashes

Copy Code code as follows:

Nssetuncaughtexceptionhandler (&uncaughtexceptionhandler);

Official Document Description: Sets the top-level error-handling function where you can perform last-minute logging the program before.
Uncaughtexceptionhandler is a function pointer that needs to be implemented to get the name we want. When a program crashes abnormally, the function gets called, which is the same as the concept of a callback function in c,c++.

2. Implement your own processing functions

Copy Code code as follows:

void Uncaughtexceptionhandler (NSException *exception) {
Nsarray *arr = [exception callstacksymbols];//get 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:%@ \ Crash reason:%@ \ n Call stack info:%@", name, Reason, arr);
}

The above code is very simple, but the effect is very large.

The above is the entire content of this article, I hope to learn about the development of iOS can help.

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.