App闪退一直是大家头疼的问题,尤其是未知的没有办法很好的做容错处理,今天就结合runloop处理崩溃问题

效果实现:

用法:
1.将截图的中CatchedHelper文件夹拖到你的项目工程中。
2.在AppDelegate.m中找到以下方法并如下添加代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[UncaughtExceptionHandler installUncaughtExceptionHandler:YES showAlert:YES];
return YES;
}
以上代码就可以实现稍微友好一点的crash拦截处理。
代码解释:
UncaughtExceptionHandler.h主要代码:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface UncaughtExceptionHandler : NSObject
/*!
* 异常的处理方法
*
* @param install 是否开启捕获异常
* @param showAlert 是否在发生异常时弹出alertView
*/
+ (void)installUncaughtExceptionHandler:(BOOL)install showAlert:(BOOL)showAlert;
@end
UncaughtExceptionHandler.m文件主要的代码如下:
1.发送异常信号
/*
* 异常的处理方法
*
* @param install 是否开启捕获异常
* @param showAlert 是否在发生异常时弹出alertView
*/
+ (void)installUncaughtExceptionHandler:(BOOL)install showAlert:(BOOL)showAlert {
if (install && showAlert) {
[[self alloc] alertView:showA

本文介绍了如何利用Runloop解决iOS App闪退问题,通过添加异常处理和信号捕获机制,实现友好的错误提示。具体步骤包括将处理文件拖入项目、设置异常和信号处理器,以及展示详细的堆栈信息。最后,通过UIAlertView提供用户可见的错误提示。
最低0.47元/天 解锁文章
1431

被折叠的 条评论
为什么被折叠?



