天天看点

iOS 崩溃日志_swift版

 //崩溃日志 第一种方法:

  NSSetUncaughtExceptionHandler(UncaughtExceptionHandler())

func UncaughtExceptionHandler() -> @convention(c) (NSException) -> Void {

        return { (exception) -> Void in

            let arr:NSArray = exception.callStackSymbols//得到当前调用栈信息

            let reason = exception.reason//非常重要,就是崩溃的原因

            let name = exception.name//异常类型

            let content =  String("===异常错误报告===:name:\(name)===\n==reson:\(reason)==\n==ncallStackSymbols:\n\(arr.componentsJoinedByString("\n"))")

            NSLog("exception type : \(name) \n crash reason : \(reason) \n call stack info : \(arr)====content-->\(content)");

        }

    }

    //第2种方法;

        NSSetUncaughtExceptionHandler { (exception) in

            print(exception.callStackSymbols)

            print(exception)

        }

继续阅读