騰訊Bugly異常崩潰SDK接入


首先登入Bugly,創建應用,記錄下AppId

①下載SDK,通過Cocoapods集成

pod 'Bugly'                                                                    #騰訊異常崩潰日志服務

②導入頭文件,並初始化

     /** 騰訊Bugly */
    #import <Bugly/Bugly.h>
    //騰訊 bugly初始化
    BuglyConfig * config = [[BuglyConfig alloc] init];
    //Debug信息開關
    config.debugMode = YES;
    config.channel = @"CallShow";
    //卡頓監控開關
    config.blockMonitorEnable = YES;
    //非正常退出事件記錄開關
    config.unexpectedTerminatingDetectionEnable = YES;
    //設置自定義日志上報的級別,默認不上報自定義日志
    config.reportLogLevel = BuglyLogLevelWarn;
    config.version = HKBuildVersion;
    [Bugly startWithAppId:BUGLY_APP_ID config:config];

③設置用戶唯一標識

[Bugly setUserIdentifier:accountInfo.openId];

④手動報告異常信息

 //開啟異常捕捉
 NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
void uncaughtExceptionHandler(NSException*exception){
    [Bugly setTag:10086];
    [Bugly reportException:exception];
    // 可以通過exception對象獲取一些崩潰信息,我們就是通過這些崩潰信息來進行解析的,例如下面的symbols數組就是我們的崩潰堆棧。
    NSArray  *callStack = [exception callStackSymbols];
    
    NSString *reason = [exception reason];
    
    NSString *name = [exception name];
    
    NSString *dateString = [NSString getTimeStamp];
    
    NSString *systemName = [[UIDevice currentDevice] systemName];//系統
    
    NSString *deviceModel = [[UIDevice currentDevice] model];//設備
    
    NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
    
    NSString *bundleIdentifier = infoDict[@"CFBundleIdentifier"];
    
    NSString* versionNum = [infoDict objectForKey:@"CFBundleShortVersionString"];
    
    NSMutableString *systemNameVersion = [[NSMutableString alloc] initWithFormat:@"%@ %@",[[UIDevice currentDevice] systemName],[[UIDevice currentDevice] systemVersion]];//手機系統版本
    //NSString *content = [NSString stringWithFormat:@"%@%@",callStack,systemNameVersion];
    NSString *content = [NSString stringWithFormat:@"\n\n\n========異常錯誤報告========\n錯誤時間:%@ 系統:%@ 設備:%@ 手機系統版本:%@ \n當前版本:%@ 當前唯一標示符:%@\n\n錯誤名稱:%@\n錯誤原因:\n%@\ncallStackSymbols:\n%@\n\n========異常錯誤結束========\n",dateString,systemName,deviceModel,systemNameVersion,versionNum,bundleIdentifier,name,reason,[callStack componentsJoinedByString:@"\n"]];
    HKLog(@"CRASH: %@", content);
    // Internal error reporting
}

⑤編寫Crash測試代碼

- (void)crashTest {
    NSArray *ary = [NSArray arrayWithObjects:@"dsfs", @"dsfsd", nil];
    NSLog(@"%@", ary[4]);  // 會觸發 uncaughtExceptionHandler 方法
}

⑥網址

https://bugly.qq.com/v2/index

https://bugly.qq.com/docs/user-guide/advance-features-ios/?v=20181014122344

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM