1.接入
1.下載SDK,導(dǎo)入庫.(此處有坑)

2.接下來就順利了

2.上傳符號(hào)表
1.什么是符號(hào)表?
符號(hào)表是內(nèi)存地址與函數(shù)名、文件名、行號(hào)的映射表。符號(hào)表元素如下所示:
<起始地址> <結(jié)束地址> <函數(shù)> [<文件名:行號(hào)>]
2.為什么要配置符號(hào)表?
為了能快速并準(zhǔn)確地定位用戶APP發(fā)生Crash的代碼位置,Bugly使用符號(hào)表對(duì)APP發(fā)生Crash的程序堆棧進(jìn)行解析和還原。
如下:
默認(rèn)Debug模式,是不會(huì)生成dSYM文件,需要開啟.重新編譯CMD+B

生成后,在哪里可以找到dSYM文件?

手動(dòng)上傳dSYM文件
把dSYM文件壓縮成zip文件,在網(wǎng)頁上上傳


上傳壓縮dSYM文件成.zip的文件即可.
例子:
上傳前:

上傳后:

官方文檔鏈接:https://bugly.qq.com/docs/user-guide/symbol-configuration-ios/?v=20160920110805
后續(xù):(保存log到本地,并上傳到Bugly管理后臺(tái))
異?;卣{(diào)處理
1.遵守代理協(xié)議<BuglyDelegate>
2.設(shè)置代理對(duì)象
BuglyConfig *config = [[BuglyConfig alloc] init];
config.delegate = self;
[Bugly startWithAppId:@"******" config:config];
3.實(shí)現(xiàn)代理方法attachmentForException
#pragma mark - Bugly代理 - 捕獲異常,回調(diào)(@return 返回需上報(bào)記錄,隨 異常上報(bào)一起上報(bào))
- (NSString *)attachmentForException:(NSException *)exception {
#ifdef DEBUG // 調(diào)試
return [NSString stringWithFormat:@"我是攜帶信息:%@",[self redirectNSLogToDocumentFolder]];
#endif
return nil;
}
#pragma mark - 保存日志文件
- (NSString *)redirectNSLogToDocumentFolder{
//如果已經(jīng)連接Xcode調(diào)試則不輸出到文件
if(isatty(STDOUT_FILENO)) {
return nil;
}
UIDevice *device = [UIDevice currentDevice];
if([[device model] hasSuffix:@"Simulator"]){
//在模擬器不保存到文件中
return nil;
}
//獲取Document目錄下的Log文件夾,若沒有則新建
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *logDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Log"];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL fileExists = [fileManager fileExistsAtPath:logDirectory];
if (!fileExists) {
[fileManager createDirectoryAtPath:logDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; //每次啟動(dòng)后都保存一個(gè)新的日志文件中
NSString *dateStr = [formatter stringFromDate:[NSDate date]];
NSString *logFilePath = [logDirectory stringByAppendingFormat:@"/%@.txt",dateStr];
// freopen 重定向輸出輸出流,將log輸入到文件
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);
return [[NSString alloc] initWithContentsOfFile:logFilePath encoding:NSUTF8StringEncoding error:nil];
}
更多高級(jí)功能參考官方文檔
https://bugly.qq.com/docs/user-guide/advance-features-ios/?v=20160930152416
/**
* 上報(bào)自定義異常
*
* @param exception 異常信息
*/
+ (void)reportException:(nonnull NSException *)exception;
/**
* 上報(bào)錯(cuò)誤
*
* @param error 錯(cuò)誤信息
*/
+ (void)reportError:(NSError *)error;
/**
* @brief 上報(bào)自定義錯(cuò)誤
*
* @param category 類型(Cocoa=3,CSharp=4,JS=5,Lua=6)
* @param aName 名稱
* @param aReason 錯(cuò)誤原因
* @param aStackArray 堆棧
* @param info 附加數(shù)據(jù)
* @param terminate 上報(bào)后是否退出應(yīng)用進(jìn)程
*/
+ (void)reportExceptionWithCategory:(NSUInteger)category name:(NSString *)aName reason:(NSString *)aReason callStack:(NSArray *)aStackArray extraInfo:(NSDictionary *)info terminateApp:(BOOL)terminate;
