• 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;
    }
  • 相关阅读:
    随机生成密码
    vue 仿新闻项目笔记
    vuex 随笔
    SourceTree
    vue npm,Git随笔
    谷歌浏览器如何去掉自动填充的背景色
    hold 命令
    ind2vec和vec2ind函数
    稀疏矩阵(sparse matrix)
    第五篇 学习OpenCV之视频处理
  • 原文地址:https://www.cnblogs.com/airy99/p/4409926.html
Copyright © 2020-2023  润新知