首先我们整理常常会闪退的异常哪些:数组越界、空引用、引用没有定义方法、内存空间不足等等。

怎样获取crash闪退日志 -- 工具查看

先看第一个问题怎样查看,我搜索的方法有下面几个:

第一个方法:XCode  的菜单Window->Organizer    选择Devices  ->  选中的手机 -> 点击手机名称左边的箭头 会等到例如以下图

注意对照一下红色框框内容,这个日志也基本上上告诉你crash的原因了。

另外一种方法 打开手机 - > 设置 -> 隐私 - > 诊断与用量 - > 诊断与用量数据  这里面就是全部应用的Crash日志。

第三种方法 通过iTunes Connect(Manage Your Applications - View Details - Crash Reports)获取用户的crash日志。方法非常多这里不多列了。

解析crash

參见:http://stackoverflow.com/questions/1460892/symbolicating-iphone-app-crash-reports )

用程序获取crash日志

可是这里都是工具,没实用到程序获取,经过千方百计的查询(思路是:先找到存放crash的iphone系统路径:var/mobile/Library/Logs/CrashReporter)找到了crash存放的路径。唉,苦于无法读取(用程序读出来都是nil)。当然假设是越狱手机就不一样是能够读取的。这个思路断掉了。

换个思路:自己用程序捕获crash。保存到本地能够吗?这么一试,果然........

第一步:新建一个继承自NSObject的类(Xcode新建一个空项目过程略),取名字CatchCrash,在h和m文件里写下:

.h文件

  1. #import <Foundation/Foundation.h>

  2. @interface CatchCrash : NSObject

  3. void uncaughtExceptionHandler(NSException *exception);

  4. @end

.m文件

  1. #import "CatchCrash.h"

  2. @implementation CatchCrash

  3. void uncaughtExceptionHandler(NSException *exception)

  4. {

  5. // 异常的堆栈信息

  6. NSArray *stackArray = [exception callStackSymbols];

  7. // 出现异常的原因

  8. NSString *reason = [exception reason];

  9. // 异常名称

  10. NSString *name = [exception name];

  11. NSString *exceptionInfo = [NSString stringWithFormat:@"Exception reason:%@\nException name:%@\nException stack:%@",name, reason, stackArray];

  12. NSLog(@"%@", exceptionInfo);

  13. NSMutableArray *tmpArr = [NSMutableArray arrayWithArray:stackArray];

  14. [tmpArr insertObject:reason atIndex:0];

  15. //保存到本地  --  当然你能够在下次启动的时候,上传这个log

  16. [exceptionInfo writeToFile:[NSString stringWithFormat:@"%@/Documents/error.log",NSHomeDirectory()]  atomically:YES encoding:NSUTF8StringEncoding error:nil];

  17. }

  18. @end

第二步:加入一个继承自UIViewcontroller的类,取名字为TestViewController。

第三步:注冊CatchCrash异常处理方法,在Appdelegate写下例如以下代码:

  1. #import "AppDelegate.h"

  2. #import "CatchCrash.h"

  3. #import "TestViewController.h"

  4. @implementation AppDelegate

  5. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

  6. {

  7. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

  8. // Override point for customization after application launch.

  9. //注冊消息处理函数的处理方法

  10. NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

  11. TestViewController *testVc = [[TestViewController alloc] init];

  12. self.window.rootViewController = testVc;

  13. self.window.backgroundColor = [UIColor whiteColor];

  14. [self.window makeKeyAndVisible];

  15. return YES;

  16. }

第四部:在TestViewController的Xib上面加入一个button并给其加入一个单击事件。TestViewController.m文件里有例如以下代码:

  1. #import "TestViewController.h"

  2. @interface TestViewController ()

  3. @end

  4. @implementation TestViewController

  5. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

  6. {

  7. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

  8. if (self) {

  9. // Custom initialization

  10. }

  11. return self;

  12. }

  13. - (void)viewDidLoad

  14. {

  15. [super viewDidLoad];

  16. // Do any additional setup after loading the view from its nib.

  17. }

  18. - (void)didReceiveMemoryWarning

  19. {

  20. [super didReceiveMemoryWarning];

  21. // Dispose of any resources that can be recreated.

  22. }

  23. #pragma mark - 单击事件

  24. - (IBAction)crashTapped:(id)sender

  25. {

  26. //常见异常1---不存在方法引用

  27. //    [self performSelector:@selector(thisMthodDoesNotExist) withObject:nil];

  28. //常见异常2---键值对引用nil

  29. //    [[NSMutableDictionary dictionary] setObject:nil forKey:@"nil"];

  30. //常见异常3---数组越界

  31. [[NSArray array] objectAtIndex:1];

  32. //常见异常4---memory warning 级别3以上

  33. //    [self performSelector:@selector(killMemory) withObject:nil];

  34. //其它大家去想吧

  35. }

  36. #pragma mark - custom method

  37. - (void) killMemory

  38. {

  39. for (int i = 0; i < 300; i ++)

  40. {

  41. UILabel *tmpLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];

  42. tmpLabel.layer.masksToBounds = YES;

  43. tmpLabel.layer.cornerRadius = 10;

  44. tmpLabel.backgroundColor = [UIColor redColor];

  45. [self.view addSubview:tmpLabel];

  46. }

  47. }

  48. @end

执行代码:能够看到闪退,导出error日志,我们能够看到:

  1. Exception reason:NSRangeException

  2. <span style="color:#FF0000;">Exception name:*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds for empty array</span>

  3. Exception stack:(

  4. 0   CoreFoundation                      0x2f2edfeb <redacted> + 154

  5. 1   libobjc.A.dylib                     0x39b66ccf objc_exception_throw + 38

  6. 2   CoreFoundation                      0x2f224a89 <redacted> + 176

  7. <span style="color:#FF0000;"> 3   TestCrash                           0x000e8077 -[TestViewController crashTapped:] + 126</span>

  8. 4   UIKit                               0x31b3f057 <redacted> + 90

  9. 5   UIKit                               0x31b3eff7 <redacted> + 30

  10. 6   UIKit                               0x31b3efd1 <redacted> + 44

  11. 7   UIKit                               0x31b2a737 <redacted> + 374

  12. 8   UIKit                               0x31b3ea4f <redacted> + 590

  13. 9   UIKit                               0x31b3e721 <redacted> + 528

  14. 10  UIKit                               0x31b396eb <redacted> + 758

  15. 11  UIKit                               0x31b0e8ed <redacted> + 196

  16. 12  UIKit                               0x31b0cf97 <redacted> + 7102

  17. 13  CoreFoundation                      0x2f2b925b <redacted> + 14

  18. 14  CoreFoundation                      0x2f2b872b <redacted> + 206

  19. 15  CoreFoundation                      0x2f2b6f1f <redacted> + 622

  20. 16  CoreFoundation                      0x2f221f0f CFRunLoopRunSpecific + 522

  21. 17  CoreFoundation                      0x2f221cf3 CFRunLoopRunInMode + 106

  22. 18  GraphicsServices                    0x3417a663 GSEventRunModal + 138

  23. 19  UIKit                               0x31b6d16d UIApplicationMain + 1136

  24. 20  TestCrash                           0x000e810d main + 116

  25. 21  libdyld.dylib                       0x3a073ab7 <redacted> + 2

  26. )

版权声明:本文博主原创文章。博客,未经同意不得转载。

iOS Crash获取闪回日志和上传server的更多相关文章

  1. Oracle Flashback Technologies - 估算不同时间段闪回日志的产生量

    Oracle Flashback Technologies - 估算不同时间段闪回日志的产生量 v$flashback_database_stat监控闪回数据的i/o开销的统计信息,根据之前的系统负载 ...

  2. ORACLE数据库闪回日志写满

    网站页面无法显示完整.检查web服务是正常的,所以可能是ORACLE数据库出了问题. 首先检查闪回日志写满 然后检查归档日志文件写满的缘故了.使用以下几个命令可以看出当前归档日志文件的使用情况: se ...

  3. oracle修改闪回日志的位置

    改变闪回日志位置的步骤: A.Change the value of the DB_RECOVERY_FILE_DEST initialization parameter to a new value ...

  4. iOS Crash 分析 符号化崩溃日志

    参考: http://blog.csdn.net/diyagoanyhacker/article/details/41247367 http://blog.csdn.net/diyagoanyhack ...

  5. Oracle 六闪回技术,flashback

    Flashback 技术基于Undo segment基于内容的, 因此,限制UNDO_RETENTON参数. 要使用flashback 特征,您必须启用自己主动撤销管理表空间. 在Oracle 11g ...

  6. 【DG】利用闪回数据库(flashback)修复Failover后的DG环境

    利用闪回数据库(flashback)修复Failover后的DG环境 1.1  BLOG文档结构图 1.2  前言部分 1.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能, ...

  7. FlashBack 闪回

    [学习目标] Flashback Database 功能非常类似与RMAN的不完全恢复,它可以把整个数据库回退到 过去的某个时点的状态,这个功能依赖于Flashback log日志.比RMAN 更快速 ...

  8. oracle 闪回功能详解

    Oracle的闪回技术提供了一组功能,可以访问过去某一时间的数据并从人为错误中恢复.闪回技术是Oracle 数据库独有的,支持任何级别的恢复,包括行.事务.表和数据库范围.使用闪回特性,您可以查询以前 ...

  9. Oracle 闪回总结

    一.闪回查询(Flashback Query)1.闪回查询技术1.1 闪回查询机制    闪回查询是指利用数据库回滚段存放的信息查看指定表中过去某个时间点的数据信息,或过去某个时间段数据的变化情况,或 ...

随机推荐

  1. osgEarth开发之OSG解构——失败的尝试

    概述 本文在吸收了<最长的一帧>以及相关参考资料的基础之上解读OSG的基础数据结构,渲染方法. 实现 在这第一部分里,要理解的是run函数的实现,因为以下这一段证明了它的重要性和强大的能力 ...

  2. 一个用 C 语言写的迷你版 2048 游戏,仅仅有 500个字符

    Jay Chan 用 C 语言写的一个迷你版 2048 游戏,仅仅有 487 个字符. 来围观吧 M[16],X=16,W,k;main(){T(system("stty cbreak&qu ...

  3. 理解Lambda表达式

    1.什么是Lambda表达式 Lambda表达式是一个匿名方法,通常在LINQ中被用来创建委托 简单来说.它是一个没有声明,没有访问修饰符,没有返回值.甚至没有名字的方法. 2.为什么我们需要使用La ...

  4. Windbg的gflags.exe -- Attach调试利器

    有没有碰到过程序启动就因为异常直接crash?有没有碰到程序启动之后什么反应也没有?有没有碰到过程序启动之后去触发另一个进程失败?有没有碰到别人的程序调用了你的代码,出现问题以后,让你来调查,而你只有 ...

  5. (读书笔记).NET大局观-.NET语言(1)

    通用语言运行时 通用语言运行时被明确设计为支持多种语言,一般而言,建立于CLR之上的语言可以获得共同的良好处理.通过一个宏大的核心语义集,CLR还界定了一个以它为基础的典型编程语言的大体部分.例如对于 ...

  6. C#同步SQL Server数据库中的数据--数据库同步工具[同步新数据]

    C#同步SQL Server数据库中的数据 1. 先写个sql处理类: using System; using System.Collections.Generic; using System.Dat ...

  7. Javascript新手集中营

        javascript是世界上最流行的编程语言,也许没有之一,看看github,stackoverflow上面的开源项目和问答就可略知一二.它可以用来开发web app.服务器.或者联合nati ...

  8. 不知道的JavaScript

    你不知道的JavaScript上卷笔记 前言 You don't know JavaScript是github上一个系列文章  初看到这一标题的时候,感觉怎么老外也搞标题党,用这种冲突性比较强的题目吸 ...

  9. Semaphore实现Andoird版源代码剖析

    Semaphore是一个计数的信号量.从概念上来说,信号量维持一组许可(permits).acquire方法在必须的时候都会堵塞直到有一个许可可用,然后就会拿走这个许可.release方法加入一个许可 ...

  10. 【CSS3】transform-origin原点旋转

    忙乱, 点 -moz-transform-origin: 0 0; -webkit-transform-origin:0 0; -o-transform-origin:0 0; 以右上角给原点 -mo ...