When the app crashes, the development phase can typically track crash information in the following ways
#1. Emulator run, view Xcode error log
#2. Real-Machine debugging, viewing the Xcode error log
#3. Real-computer operation, view device system logs
For example, write a crash code Crashdemo:
-(void) viewdidload { [super Viewdidload]; // additional setup after loading the view, typically from a nib. [Self performselector: @selector (print) Withobject:nil afterdelay:5];} -(void) print { *array = @[]; NSLog (@ "%@", array[1]);}
Demo#1. Emulator run, view Xcode error log
The program will crash immediately after execution, open the Xcode system log to see the following error message
.-Ten- in A: -:29.015crashdemo[37842:7436441] * * * * terminating app due to uncaught exception'nsrangeexception', Reason:'* * *-[__nsarray0 Objectatindex:]: Index 1 beyond bounds for empty Nsarray'***First throw Call stack: (0Corefoundation0x00b7ba84__exceptionpreprocess + the 1LIBOBJC. A.dylib0X00642E02Objc_exception_throw + - 2Corefoundation0x00b22390__cfarraygettypeid_block_invoke +0 3Corefoundation0x00ac07f8-[nsarray Objectatindexedsubscript:] + + 4Crashdemo0x000877b7-[viewcontroller Print] + the 5Foundation0x00250d71__nsfiredelayedperform +442 6Corefoundation0x00acd576__cfrunloop_is_calling_out_to_a_timer_callback_function__ + A 7Corefoundation0x00accf72__cfrunloopdotimer +1250 8Corefoundation0x00a8b25a__cfrunlooprun +2202 9Corefoundation0x00a8a706Cfrunlooprunspecific +470 TenCorefoundation0x00a8a51bCfrunloopruninmode +123 OneGraphicsservices0x041e4664Gseventrunmodal +192 AGraphicsservices0X041E44A1Gseventrun +104 -UIKit0x00f0c1ebUiapplicationmain + the -Crashdemo0x00087bbaMain +138 theLibdyld.dylib0x03189a21Start +1) libc++abi.dylib:terminating with uncaught exception of type nsexception (LLDB)
For this demo we are of course very clear that the array[1 in the previous column has crossed the line, but how does a complete program see where the cross-border occurs?
This time we can use Xcode's show the Breakpoint Navigator feature, click the plus sign to select Add Exception breakpoint
This time we are executing the program, Xcode execution will automatically stop at the code snippet where the crash will occur
Demo#2. Real-Machine debugging, viewing the Xcode error log
If you add Exeception point, the program will automatically stop to the line where you print array[1]. If you do not add the program will crash, Xcode will receive the following error log
.-Ten- in A: the:53.561crashdemo[1062:316582] * * * * terminating app due to uncaught exception'nsrangeexception', Reason:'* * *-[__nsarray0 Objectatindex:]: Index 1 beyond bounds for empty Nsarray'***First throw Call stack: (0x211b398b 0x2094ee17 0x211433e7 0xc5a3b 0x219d1ad5 0x211765ff 0x21176231 0x2117407d 0x210c32e9 0x210c30d5 0X226B3AC9 0x257880b9 0xc5c99 0x20d6b873) libc++abi.dylib:terminating with uncaught exception of type nsexception (LLDB)
Through the error message we can only see that there is an array of access out of bounds, if there is added Exeception breakpoint will automatically stop in the line of code where the error occurred.
Demo#3. Real machine run, view device system log
Xcode stops running this crashdemo, select Xcode window-devices, select phone-View device logs
Then run Crashdemo on your phone and check the latest log in device logs by Time to see the Crashdemo crash log
Incident identifier:9a4c52f0-b0d7-42c9-a7cb-d4d3321d00d5crashreporter key:90f4d3621773443794fa73f506fd6bdef49fc269hardware model:iphone4,1Process:crashdemo [1074]path:/private/var/containers/bundle/application/1307034e-9c2b-451f-acd9-04c97dec047b/crashdemo.app/Crashdemoidentifier:pega. Crashdemoversion:1(1.0) Code type:arm (Native) Parent Process:launchd [1]date/time: .-Ten- in A: +:49.49+0800Launch Time: .-Ten- in A: +:43.43+0800OS Version:ios9.3.1(13E238) Report Version:104Exception Type:exc_crash (SIGABRT) Exception Codes:0x0000000000000000,0x0000000000000000Exception note:exc_corpse_notifytriggered by Thread:0Filtered syslog:none foundlast Exception backtrace:0Corefoundation0x211b3986__exceptionpreprocess +1221LIBOBJC. A.dylib0x2094ee12Objc_exception_throw + the2Corefoundation0x211433e2-[__nsarray0 Objectatindex:] + the3Crashdemo0x000e6a36 0xe0000+271904Foundation0x219d1ad0__nsfiredelayedperform +4645Corefoundation0X211765FA
These are easy to implement during the development phase, but when the app is released, the user crash. The average user can only feedback when doing what happens crash
Then we are going to try to see if we can meet, but this is not very efficient and generally difficult to replicate to the user's crash
The emergence of bugly solves this problem
The Bugly SDK automatically sends error messages to the server when a program crashes, allowing developers to view the analysis
So how to use bugly?
First go to https://bugly.qq.com/v2/to register your account, and register for the app Download SDK package
Drag the bugly.framework to the project and check the copy if needed.
Then add libz.tbd/libstdc++.tbd/security.framework/systemconfiguration.framework to the project
Register in DELEGATE.M
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions { [bugly startwithappid:@ " replace here with your AppID"]; return YES; }
So when the program crashes, the crash information is automatically sent to the server to log in to your bugly account and you can see it.
IOS crash general tracking method and bugly integration application