在启动时检测应用程序崩溃

我看到一些应用程序检测应用程序是否最后一次崩溃,以鼓励用户报告错误。

我怎样才能做到这一点? 我试过这个解决scheme ,但没有得到它在我的迅速项目中工作…
我想到的一种方法是每次应用即将closures时保存一些内容,然后在启动应用程序时读取值,我猜应用程序崩溃时将无法保存任何内容,对不对?
但是,这不是很优雅。 有没有更好的方法来检测崩溃?

提前致谢 :)

您可以使用内联closures在崩溃期间执行日志logging。

 NSSetUncaughtExceptionHandler { exception in // Do necessary logging work here } 

这SO线程可能会帮助你..

你可以通过twitter使用crashlytics。

  1. 下载面料mac应用程序
  2. 打开它并注册一个新的帐户
  3. 将您的xcode项目添加到结构中的项目列表
  4. select将crashlytics框架添加到您的应用程序
  5. build立你的应用程序
  6. 查看给定的代码片段以crashlytics开头
  7. 访问Fabric文档获取更多信息
 import XCPlayground import Foundation let fm = NSFileManager() if fm.fileExistsAtPath("terminated") { try! fm.removeItemAtPath("terminated") } else { print("an app crashed last time") } // set i to nil to force the app to crash // than set it to 0 and execute it again let i: Int! = 0 let j: Int = i fm.createFileAtPath("terminated", contents: nil, attributes: nil) print("terminated")