程序崩溃分析报告

在代码中添加try catch 拦截异常,可以在main.m中添加代码

  • 第一种方式 ```objc

    import

    import "AppDelegate.h"

int main(int argc, char argv[]) { @try { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } @catch (NSException exception) { // 将异常信息保存到沙河中,下次打开程序将错误信息传给服务器 NSLog(@"%@",exception); } @finally {

}

}```

  • 第二种方式
/**
 *   拦截异常
 */
void handleException(NSException * expetion) {
    [expetion callStackSymbols]; // 调用栈信息(错误来源于哪个方法)
    [expetion name]; // 异常名字
    [expetion reason]; // 异常描述(报错的理由)
    NSMutableDictionary * info = [NSMutableDictionary dictionary];
    info[@"callStack"] = [expetion callStackSymbols];
    info[@"name"] = [expetion name];
    info[@"reason"] = [expetion reason];
    [info writeToFile:<#(nonnull NSString *)#> atomically:<#(BOOL)#>]

}

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

    // 设置捕捉异常的回调
    NSSetUncaughtExceptionHandler(handleException);

    return YES;
}

崩溃统计也可以用三方集成

/**
 *  崩溃统计
 *  1.友盟
 *  2.Flurry
 *  3.Crashlytics
 */

程序假死状态

 /**
 *   拦截异常
 */
void handleException(NSException * expetion) {

    UIAlertView * view = [[UIAlertView alloc] initWithTitle:@"哈哈" message:@"懵逼了吧" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [view show];

    // 因为这个时候RunLoop已经死了,所以需要重新开启
    // 重新启动RunLoop
    [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:NSDefaultRunLoopMode];
    [[NSRunLoop currentRunLoop] run];
}

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

    // 设置捕捉异常的回调
    NSSetUncaughtExceptionHandler(handleException);

    return YES;
}

弹框之后退出程序

#import "AppDelegate.h"

@interface AppDelegate ()<UIAlertViewDelegate>

@end

@implementation AppDelegate


/**
 *  崩溃统计
 *  1.友盟
 *  2.Flurry
 *  3.Crashlytics
 */

/**
 *   拦截异常:因为是函数,所以没有self
 */
void handleException(NSException * expetion) {

    [[UIApplication sharedApplication].delegate performSelector:@selector(hand)];
}

- (void)hand {

    UIAlertView * view = [[UIAlertView alloc] initWithTitle:@"哈哈" message:@"懵逼了吧" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [view show];

    // 因为这个时候RunLoop已经死了,所以需要重新开启
    // 重新启动RunLoop
    [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:NSDefaultRunLoopMode];
    [[NSRunLoop currentRunLoop] run];
}

#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    // 退出程序
    exit(0);
}

results matching ""

    No results matching ""