网上没找到Swift版本的,都是Objective C的. 分享一个原创的swift版本的. 下面都是贴出来部分代码.
#if DEBUG || ALPHA
fileprivate func showCrashAlert(ctx:[String:Any]){
DispatchQueue.main.async {
let alertVC = UIAlertController.init(title: "崩溃了", message: ctx.jsonString(prettify: true) ?? "", preferredStyle: .alert)
alertVC.addAction(.init(title: "确定退出", style: .destructive, handler: { _ in
isExit = true
exit(-1)
}))
UIApplication.shared.keyWindow?.rootViewController?.present(alertVC, animated: true, completion: nil)
}
// 弹窗提示 崩溃
while (!isExit) {
Xlog(msg: "进入runloop")
if let modes = CFRunLoopCopyAllModes(CFRunLoopGetCurrent()){
for i in 0..<CFArrayGetCount(modes){
let mode = CFArrayGetValueAtIndex(modes, i) as! CFRunLoopMode
CFRunLoopRunInMode(mode, 0.001, false)
}
}
}
}
#endif