在發布階段,假如用戶的 App 發作了閃退,也就是解體了。我們應該如何得知,應該如何無效搜集這些解體的日志信息。以助於我們的 App 更好的優化。
去 GitHub 下載一個框架:WZYCrash
https://github.com/CoderZYWang/WZYCrash
將 WZYCrash 集成到自己的項目中去。
//
// AppDelegate.m
// WZYCrashDemo
//
// Created by CoderZYWang on 2016/12/30.
// Copyright © 2016年 wzy. All rights reserved.
//
#import "AppDelegate.h"
#import "WZYCrashHandler.h"
#import "WZYUncaughtExceptionHandler.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 捕捉解體日志
[WZYUncaughtExceptionHandler setDefaultHandler];
// 上傳解體日志到服務器
[WZYCrashHandler uploadCrashLog];
return YES;
}
@end
然後我們就可以用我們的代碼停止測試,可以先自己寫一個小錯誤然後測試一下能否集成成功。
//
// ViewController.m
// WZYCrashDemo
//
// Created by CoderZYWang on 2016/12/30.
// Copyright © 2016年 wzy. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 測試代碼(運轉demo時翻開)
// 數組越界錯誤
// NSArray *arr = @[@"123"];
// NSLog(@"%@", arr[3]);
// 再次運轉順序,在崩掉之前會有我們的打印信息(str 就是我們搜集的錯誤信息)
/*
2016-12-30 14:14:26.883423 WZYCrashDemo[2693:1047098] str ---
- IDENTIFIER_NUMBER: 6185368C-0054-49C6-8614-F91EA96A5FF3
- OSVERSION: 10.0.2
- PHONE_TYPE: iPhone 6s
- APP_VERSION: 1.0
- name:
NSRangeException
- reason:
*** -[__NSSingleObjectArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 0]
- callStackSymbols:
0 CoreFoundation 0x00000001844181d8 <redacted> + 148
1 libobjc.A.dylib 0x0000000182e5055c objc_exception_throw + 56
2 CoreFoundation 0x0000000184409428 <redacted> + 0
3 WZYCrashDemo 0x00000001000d3178 -[ViewController viewDidLoad] + 188
4 UIKit 0x000000018a2613dc <redacted> + 1056
5 UIKit 0x000000018a260fa4 <redacted> + 28
6 UIKit 0x000000018a267750 <redacted> + 76
7 UIKit 0x000000018a264bf0 <redacted> + 272
8 UIKit 0x000000018a2d7414 <redacted> + 48
9 UIKit 0x00000
*/
}
@end
【Xcode 【發布形態下怎樣捕捉解體日志上傳到服務器】】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!