iOS Crash常规跟踪方法及Bugly集成运用详细介绍

2025-05-29 0 101

ios crash常规跟踪方法及bugly集成运用

当app出现崩溃, 研发阶段一般可以通过以下方式来跟踪crash信息

#1.模拟器运行, 查看xcode错误日志

#2.真机调试, 查看xcode错误日志

#3.真机运行, 查看device系统日志

下面举例说明, 先写一段会crash的代码crashdemo:

?

1

2

3

4

5

6

7

8

9

10
- (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.模拟器运行, 查看xcode错误日志

程序执行后会立即崩溃, 打开xcode系统日志可以看到以下错误信息

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22
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)

通过xcode日志可以看到是数组访问越界, 发生越界的方式名为print

针对这个demo我们当然很清楚是刚才列的array[1]发生越界, 但对于一个完整的程序如何查看是在哪个地方发生越界的呢?

这个时候我们可以利用xcode的show the breakpoint navigator功能, 点加号选择add exception breakpoint

这个时候我们在执行程序, xcode执行会自动停在要发生crash的代码段

demo#2.真机调试, 查看xcode错误日志
如果有添加exeception point, 程序会自动停到打印array[1]那一行. 如果没有添加则程序会crash, xcode会出现以下错误日志

?

1

2

3

4

5
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)

通过错误信息我们只能看到是有发生数组访问越界, 如果有添加exeception breakpoint则会自动停在发生error的代码行.

demo#3. 真机运行, 查看device系统日志

xcode停止运行这个crashdemo, 选择xcode window – devices, 选择手机 – view device logs

然后在手机上运行crashdemo, 在device logs中按时间排序查看最新的log就能看到crashdemo的crash log

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30
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

这些在开发阶段都能很简便的实现, 但是当app发布出去后用户发生crash呢? 一般用户只能反馈在做什么的时候发生crash

然后我们在去做尝试是否能遇到, 不过这样效率不高而且一般很难复现到用户的crash

bugly的出现解决的这个问题

bugly sdk在当程序崩溃时, 会自动将错误信息发送到服务器方便开发人员查看分析

那么如何使用bugly?

首先先到https://bugly.qq.com/v2/注册账号, 并注册app下载sdk包

将bugly.framework拖拽到工程中, 记得勾选copy if needed.

然后添加libz.tbd / libstdc++.tbd / security.framework / systemconfiguration.framework到工程中

delegate.m中注册

?

1

2

3

4
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {

[bugly startwithappid:@"此处替换为你的appid"];

return yes;

}

这样当程序发生崩溃时, 崩溃信息会自动发送到服务器登录你的bugly账号就能查看到了

iOS Crash常规跟踪方法及Bugly集成运用详细介绍

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 iOS Crash常规跟踪方法及Bugly集成运用详细介绍 https://www.kuaiidc.com/92487.html

相关文章

发表评论
暂无评论