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;
    }
  • 相关阅读:
    设计模式之模式方法模式
    Extjs 分页多选的实现
    设计模式之策略模式
    oracle 12c 报错 ora-03137 来自客户机的格式错误的TTC包被拒绝
    设计模式之状态模式
    设计模式之装饰者模式
    设计模式之代理模式
    设计模式之单例模式
    从reduce函数说起...
    Django View(视图系统)
  • 原文地址:https://www.cnblogs.com/airy99/p/4409926.html
Copyright © 2011-2022 走看看