iOS开发学习之监测程序的崩溃次数详解

2020-01-21 00:08:57王旭

// 弹出升级警告

- (void)showAlertAction{

UIAlertController*alert

=

[UIAlertControlleralertControllerWithTitle:@"警告"message:@"检测到软件多次异常退出,建议您尽快更新到最新版本!" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction*sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefaulthandler:nil];

[alert addAction:sure];

[self.window.rootViewController presentViewController:alert animated:YES completion:nil];

}

为了方便大家直接使用,我已经将实现代码封装为一个小框架,只需使用一句代码即可调用。

github下载地址: https://www.easck.com/p>


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

 // 参数crashCount为崩溃多少次后执行block中的代码
 [[JJRecordCrash shareInstance] recordCrashWithCrashCount:2 handle:^{
  // 多次崩溃后执行自己想执行的代码,如:清除缓存 提示用户更新
  NSLog(@"崩溃啦");
 }];

 return YES;
}

注意:调试时,在程序运行中直接使用xcode重新运行程序,因为不会走- (void)applicationWillTerminate:(UIApplication*)application方法,所以也相当于是崩溃,同样会被记录下来。

总结

以上就是这篇文章的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对ASPKU的支持。


注:相关教程知识阅读请移步到IOS开发频道。