上传崩溃报告后清除本地之前的信息
This commit is contained in:
parent
7b4428e416
commit
8c9eda876f
@ -48,6 +48,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
if data != nil {
|
if data != nil {
|
||||||
let crushStr:String? = String.init(data: data! as Data, encoding: String.Encoding.utf8)
|
let crushStr:String? = String.init(data: data! as Data, encoding: String.Encoding.utf8)
|
||||||
Analytics.logEvent("app_crash", parameters: ["crashInfo":crushStr ?? ""])
|
Analytics.logEvent("app_crash", parameters: ["crashInfo":crushStr ?? ""])
|
||||||
|
CopyCrashHandler.cleanCrashInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,78 +6,24 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
//public class CopyCrashHandler
|
|
||||||
//{
|
|
||||||
// public static func setup(callBack:@escaping CrashCallback){
|
|
||||||
// crashCallBack = callBack;
|
|
||||||
// registerSignalHanlder();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//public typealias Completion = ()->Void;
|
|
||||||
//public typealias CrashCallback = (String,Completion)->Void;
|
|
||||||
//
|
|
||||||
//public var crashCallBack: CrashCallback?
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//func signalHandler(signal:Int32) -> Void {
|
|
||||||
// let stackTrace = Thread.callStackSymbols.joined(separator: "\r\n")
|
|
||||||
// crashCallBack?(stackTrace,{
|
|
||||||
// unregisterSignalHandler();
|
|
||||||
// exit(signal);
|
|
||||||
// });
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func registerSignalHanlder()
|
|
||||||
//{
|
|
||||||
// objc_setUncaughtExceptionHandler { (_response:Any?) in
|
|
||||||
// if let signal = _response as? Int32 {
|
|
||||||
// signalHandler(signal: signal)
|
|
||||||
// }
|
|
||||||
// else if let exception = _response as? NSException {
|
|
||||||
// crashCallBack?(exception.reason ?? exception.callStackSymbols.joined(separator: "\r\n"),{
|
|
||||||
// unregisterSignalHandler();
|
|
||||||
// exception.raise()
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// signal(SIGINT, signalHandler);
|
|
||||||
// signal(SIGSEGV, signalHandler);//野指针,僵尸对象
|
|
||||||
// signal(SIGTRAP, signalHandler);
|
|
||||||
// signal(SIGABRT, signalHandler);
|
|
||||||
// signal(SIGILL, signalHandler);
|
|
||||||
// signal(SIGBUS, signalHandler);
|
|
||||||
// signal(SIGFPE, signalHandler);
|
|
||||||
// signal(SIGTERM, signalHandler);
|
|
||||||
// signal(SIGKILL, signalHandler);//CPU无法执行的代码(比如无效指令、除以0等)
|
|
||||||
// signal(SIGPIPE, signalHandler);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func unregisterSignalHandler()
|
|
||||||
//{
|
|
||||||
// signal(SIGINT, SIG_DFL);
|
|
||||||
// signal(SIGSEGV, SIG_DFL);
|
|
||||||
// signal(SIGTRAP, SIG_DFL);
|
|
||||||
// signal(SIGABRT, SIG_DFL);
|
|
||||||
// signal(SIGILL, SIG_DFL);
|
|
||||||
// signal(SIGBUS, SIG_DFL);
|
|
||||||
// signal(SIGFPE, SIG_DFL);
|
|
||||||
// signal(SIGTERM, SIG_DFL);
|
|
||||||
// signal(SIGKILL, SIG_DFL);
|
|
||||||
// signal(SIGPIPE, SIG_DFL);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
public class CopyCrashHandler {
|
public class CopyCrashHandler {
|
||||||
public class func getdataPath() -> String{
|
public class func getdataPath() -> String{
|
||||||
let str = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.cachesDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last!
|
let str = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.cachesDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last!
|
||||||
let urlPath = str.appending("Exception.txt")
|
let urlPath = str.appending("Exception.txt")
|
||||||
return urlPath
|
return urlPath
|
||||||
|
}
|
||||||
|
|
||||||
|
public class func cleanCrashInfo() {
|
||||||
|
let path = CopyCrashHandler.getdataPath()
|
||||||
|
do{
|
||||||
|
if FileManager.default.fileExists(atPath: path) {
|
||||||
|
try FileManager.default.removeItem(atPath: path)
|
||||||
|
}
|
||||||
|
}catch{
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class func setDefaultHandler() {
|
public class func setDefaultHandler() {
|
||||||
NSSetUncaughtExceptionHandler { (exception) in
|
NSSetUncaughtExceptionHandler { (exception) in
|
||||||
let arr:NSArray = exception.callStackSymbols as NSArray
|
let arr:NSArray = exception.callStackSymbols as NSArray
|
||||||
@ -95,8 +41,7 @@ public class CopyCrashHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try url.write(toFile: path, atomically: true, encoding: String.Encoding.utf8)
|
try url.write(toFile: path, atomically: true, encoding: String.Encoding.utf8)
|
||||||
}catch{ error
|
}catch{
|
||||||
print("\(error)")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user