iOS Crash常規(guī)跟蹤方法及Bugly集成運(yùn)用詳細(xì)介紹
iOS Crash常規(guī)跟蹤方法及Bugly集成運(yùn)用
當(dāng)app出現(xiàn)崩潰, 研發(fā)階段一般可以通過(guò)以下方式來(lái)跟蹤crash信息
#1.模擬器運(yùn)行, 查看xcode錯(cuò)誤日志
#2.真機(jī)調(diào)試, 查看xcode錯(cuò)誤日志
#3.真機(jī)運(yùn)行, 查看device系統(tǒng)日志
下面舉例說(shuō)明, 先寫(xiě)一段會(huì)Crash的代碼crashdemo:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self performSelector:@selector(print) withObject:nil afterDelay:5]; } - (void)print { NSArray *array = @[]; NSLog(@"%@", array[1]); }
Demo#1.模擬器運(yùn)行, 查看xcode錯(cuò)誤日志
程序執(zhí)行后會(huì)立即崩潰, 打開(kāi)xcode系統(tǒng)日志可以看到以下錯(cuò)誤信息
2016-10-29 12:13:29.015 CrashDemo[37842:7436441] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 1 beyond bounds for empty NSArray' *** First throw call stack: ( 0 CoreFoundation 0x00b7ba84 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x00642e02 objc_exception_throw + 50 2 CoreFoundation 0x00b22390 __CFArrayGetTypeID_block_invoke + 0 3 CoreFoundation 0x00ac07f8 -[NSArray objectAtIndexedSubscript:] + 40 4 CrashDemo 0x000877b7 -[ViewController print] + 87 5 Foundation 0x00250d71 __NSFireDelayedPerform + 442 6 CoreFoundation 0x00acd576 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22 7 CoreFoundation 0x00accf72 __CFRunLoopDoTimer + 1250 8 CoreFoundation 0x00a8b25a __CFRunLoopRun + 2202 9 CoreFoundation 0x00a8a706 CFRunLoopRunSpecific + 470 10 CoreFoundation 0x00a8a51b CFRunLoopRunInMode + 123 11 GraphicsServices 0x041e4664 GSEventRunModal + 192 12 GraphicsServices 0x041e44a1 GSEventRun + 104 13 UIKit 0x00f0c1eb UIApplicationMain + 160 14 CrashDemo 0x00087bba main + 138 15 libdyld.dylib 0x03189a21 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
通過(guò)xcode日志可以看到是數(shù)組訪(fǎng)問(wèn)越界, 發(fā)生越界的方式名為print
針對(duì)這個(gè)demo我們當(dāng)然很清楚是剛才列的array[1]發(fā)生越界, 但對(duì)于一個(gè)完整的程序如何查看是在哪個(gè)地方發(fā)生越界的呢?
這個(gè)時(shí)候我們可以利用xcode的Show the breakpoint navigator功能, 點(diǎn)加號(hào)選擇add exception breakpoint
這個(gè)時(shí)候我們?cè)趫?zhí)行程序, xcode執(zhí)行會(huì)自動(dòng)停在要發(fā)生crash的代碼段
Demo#2.真機(jī)調(diào)試, 查看xcode錯(cuò)誤日志
如果有添加exeception point, 程序會(huì)自動(dòng)停到打印array[1]那一行. 如果沒(méi)有添加則程序會(huì)crash, xcode會(huì)出現(xiàn)以下錯(cuò)誤日志
2016-10-29 12:15:53.561 CrashDemo[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)
通過(guò)錯(cuò)誤信息我們只能看到是有發(fā)生數(shù)組訪(fǎng)問(wèn)越界, 如果有添加exeception breakpoint則會(huì)自動(dòng)停在發(fā)生error的代碼行.
Demo#3. 真機(jī)運(yùn)行, 查看device系統(tǒng)日志
xcode停止運(yùn)行這個(gè)crashdemo, 選擇xcode window - devices, 選擇手機(jī) - view device logs
然后在手機(jī)上運(yùn)行crashdemo, 在device logs中按時(shí)間排序查看最新的log就能看到crashdemo的crash log
Incident Identifier: 9A4C52F0-B0D7-42C9-A7CB-D4D3321D00D5 CrashReporter Key: 90f4d3621773443794fa73f506fd6bdef49fc269 Hardware Model: iPhone4,1 Process: CrashDemo [1074] Path: /private/var/containers/Bundle/Application/1307034E-9C2B-451F-ACD9-04C97DEC047B/CrashDemo.app/CrashDemo Identifier: PEGA.CrashDemo Version: 1 (1.0) Code Type: ARM (Native) Parent Process: launchd [1] Date/Time: 2016-10-29 12:21:49.49 +0800 Launch Time: 2016-10-29 12:21:43.43 +0800 OS Version: iOS 9.3.1 (13E238) Report Version: 104 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Triggered by Thread: 0 Filtered syslog: None found Last Exception Backtrace: 0 CoreFoundation 0x211b3986 __exceptionPreprocess + 122 1 libobjc.A.dylib 0x2094ee12 objc_exception_throw + 34 2 CoreFoundation 0x211433e2 -[__NSArray0 objectAtIndex:] + 110 3 CrashDemo 0x000e6a36 0xe0000 + 27190 4 Foundation 0x219d1ad0 __NSFireDelayedPerform + 464 5 CoreFoundation 0x211765fa
這些在開(kāi)發(fā)階段都能很簡(jiǎn)便的實(shí)現(xiàn), 但是當(dāng)app發(fā)布出去后用戶(hù)發(fā)生crash呢? 一般用戶(hù)只能反饋在做什么的時(shí)候發(fā)生crash
然后我們?cè)谌プ鰢L試是否能遇到, 不過(guò)這樣效率不高而且一般很難復(fù)現(xiàn)到用戶(hù)的crash
Bugly的出現(xiàn)解決的這個(gè)問(wèn)題
Bugly SDK在當(dāng)程序崩潰時(shí), 會(huì)自動(dòng)將錯(cuò)誤信息發(fā)送到服務(wù)器方便開(kāi)發(fā)人員查看分析
那么如何使用Bugly?
首先先到https://bugly.qq.com/v2/注冊(cè)賬號(hào), 并注冊(cè)app下載SDK包
將Bugly.framework拖拽到工程中, 記得勾選copy if needed.
然后添加libz.tbd / libstdc++.tbd / Security.framework / SystemConfiguration.framework到工程中
delegate.m中注冊(cè)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [Bugly startWithAppId:@"此處替換為你的AppId"]; return YES; }
這樣當(dāng)程序發(fā)生崩潰時(shí), 崩潰信息會(huì)自動(dòng)發(fā)送到服務(wù)器登錄你的bugly賬號(hào)就能查看到了
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- Android 使用騰訊X5瀏覽器上傳圖片的示例
- Android 通過(guò)騰訊TBS實(shí)現(xiàn)文件預(yù)覽功能
- Android基于騰訊云實(shí)時(shí)音視頻仿微信視頻通話(huà)最小化懸浮
- Android集成騰訊X5實(shí)現(xiàn)文檔瀏覽功能
- Android自定義View仿騰訊TIM下拉刷新View
- Android在項(xiàng)目中接入騰訊TBS瀏覽器WebView的教程與注意的地方
- Android實(shí)現(xiàn)視頻播放--騰訊瀏覽服務(wù)(TBS)功能
- Android開(kāi)發(fā)騰訊驗(yàn)證碼遇到的坑
- 騰訊、百度、華為、搜狗和滴滴Android面試題匯總
- Android如何快速集成騰訊Bugly
相關(guān)文章
iOS App開(kāi)發(fā)中通過(guò)UIDevice類(lèi)獲取設(shè)備信息的方法
UIDevice最常見(jiàn)的用法就是用來(lái)監(jiān)測(cè)iOS設(shè)備的電量了,然后再實(shí)現(xiàn)電池狀態(tài)通知非常方便,除此之外還有傳感器等信息的獲取,這里我們就來(lái)總結(jié)一下iOS App開(kāi)發(fā)中通過(guò)UIDevice類(lèi)獲取設(shè)備信息的方法:2016-07-07詳解iOS應(yīng)用程序的啟動(dòng)過(guò)程
這篇文章主要介紹了iOS應(yīng)用程序的啟動(dòng)過(guò)程,講述了從其執(zhí)行main函數(shù)開(kāi)始到展示UIWindow的流程中的一些關(guān)鍵點(diǎn),需要的朋友可以參考下2016-03-03iOS開(kāi)發(fā)之自定義UITextField的方法
UITextField是IOS開(kāi)發(fā)中用戶(hù)交互中重要的一個(gè)控件,常被用來(lái)做賬號(hào)密碼框,輸入信息框等。本文給大家介紹iOS開(kāi)發(fā)之自定義UITextField的方法,感興趣的朋友一起學(xué)習(xí)吧2016-05-05iOS使用UICollectionView實(shí)現(xiàn)列表頭部拉伸效果
這篇文章主要介紹了iOS使用UICollectionView實(shí)現(xiàn)列表頭部拉伸效果,OC和Swift兩個(gè)版本,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05淺談iphone X的簡(jiǎn)單適配問(wèn)題(推薦)
這篇文章主要介紹了淺談iphone X的簡(jiǎn)單適配(推薦),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11UIScrollView實(shí)現(xiàn)六棱柱圖片瀏覽效果
這篇文章主要為大家介紹了UIScrollView實(shí)現(xiàn)六棱柱圖片瀏覽效果示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07