zoukankan      html  css  js  c++  java
  • iOS 崩溃日志

    #import <Foundation/Foundation.h>
    
    @interface ZRUncaughtExceptionHandler : NSObject
    
    + (void)setDefaultHandler;
    + (NSUncaughtExceptionHandler*)getHandler;
    
    @end
    #import "ZRUncaughtExceptionHandler.h"
    
    @implementation ZRUncaughtExceptionHandler
    
    NSString *applicationDocumentsDirectory() {
        return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    }
    
    void UncaughtExceptionHandler(NSException *exception) {
        NSArray *arr = [exception callStackSymbols];
        NSString *reason = [exception reason];
        NSString *name = [exception name];
        
        NSString *url = [NSString stringWithFormat:@"=============异常崩溃报告=============
    name:
    %@
    reason:
    %@
    callStackSymbols:
    %@",
                         name,reason,[arr componentsJoinedByString:@"
    "]];
        NSString *path = [applicationDocumentsDirectory() stringByAppendingPathComponent:@"Exception.txt"];
        [url writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
    }
    
    - (NSString *)applicationDocumentsDirectory {
        return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    }
    
    + (void)setDefaultHandler
    {
        NSSetUncaughtExceptionHandler (&UncaughtExceptionHandler);
    }
    
    + (NSUncaughtExceptionHandler*)getHandler
    {
        return NSGetUncaughtExceptionHandler();
    }
    
    @end

    使用如下

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        
        [ZRUncaughtExceptionHandler setDefaultHandler];
        
        return YES;
    }
  • 相关阅读:
    家庭记账本APP开发准备(二)
    使用花生壳5做内网穿透
    课堂练习之可视化的强化版
    第五周总结
    课堂练习之疫情可视化
    第四周总结
    第三周总结
    第二周总结
    课堂练习之最大子数组
    软工第二学期开课博客
  • 原文地址:https://www.cnblogs.com/airy99/p/4409926.html
Copyright © 2011-2022 走看看