服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - IOS - iOS Crash常规跟踪方法及Bugly集成运用详细介绍

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

2021-02-05 15:58iOS开发网 IOS

这篇文章主要介绍了iOS Crash常规跟踪方法及Bugly集成运用详细介绍的相关资料,需要的朋友可以参考下

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集成运用详细介绍

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

延伸 · 阅读

精彩推荐
  • IOSIOS开发之字典转字符串的实例详解

    IOS开发之字典转字符串的实例详解

    这篇文章主要介绍了IOS开发之字典转字符串的实例详解的相关资料,希望通过本文能帮助到大家,让大家掌握这样的方法,需要的朋友可以参考下...

    苦练内功5832021-04-01
  • IOS解析iOS开发中的FirstResponder第一响应对象

    解析iOS开发中的FirstResponder第一响应对象

    这篇文章主要介绍了解析iOS开发中的FirstResponder第一响应对象,包括View的FirstResponder的释放问题,需要的朋友可以参考下...

    一片枫叶4662020-12-25
  • IOSiOS中tableview 两级cell的展开与收回的示例代码

    iOS中tableview 两级cell的展开与收回的示例代码

    本篇文章主要介绍了iOS中tableview 两级cell的展开与收回的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    J_Kang3862021-04-22
  • IOSiOS布局渲染之UIView方法的调用时机详解

    iOS布局渲染之UIView方法的调用时机详解

    在你刚开始开发 iOS 应用时,最难避免或者是调试的就是和布局相关的问题,下面这篇文章主要给大家介绍了关于iOS布局渲染之UIView方法调用时机的相关资料...

    windtersharp7642021-05-04
  • IOSIOS 屏幕适配方案实现缩放window的示例代码

    IOS 屏幕适配方案实现缩放window的示例代码

    这篇文章主要介绍了IOS 屏幕适配方案实现缩放window的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要...

    xiari5772021-06-01
  • IOSiOS 雷达效果实例详解

    iOS 雷达效果实例详解

    这篇文章主要介绍了iOS 雷达效果实例详解的相关资料,需要的朋友可以参考下...

    SimpleWorld11022021-01-28
  • IOSiOS通过逆向理解Block的内存模型

    iOS通过逆向理解Block的内存模型

    自从对 iOS 的逆向初窥门径后,我也经常通过它来分析一些比较大的应用,参考一下这些应用中某些功能的实现。这个探索的过程乐趣多多,不仅能满足自...

    Swiftyper12832021-03-03
  • IOS关于iOS自适应cell行高的那些事儿

    关于iOS自适应cell行高的那些事儿

    这篇文章主要给大家介绍了关于iOS自适应cell行高的那些事儿,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的...

    daisy6092021-05-17