【问题标题】:iOS - Take screenshot before app crashesiOS - 在应用程序崩溃之前截取屏幕截图
【发布时间】:2015-11-14 06:39:15
【问题描述】:

有什么方法可以在应用崩溃前截取屏幕截图。我正在使用此代码截屏,但如何知道应用程序何时崩溃?

func screenShotMethod() {

    //Create the UIImage
    UIGraphicsBeginImageContext(view.frame.size)
    view.layer.renderInContext(UIGraphicsGetCurrentContext())
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    //Save it to the camera roll
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}

【问题讨论】:

  • 在本机中,您可以为此使用测试用例,但您的问题是您需要屏幕截图,然后您需要进行一些第三方测试用例,这些图像和视频也会显示在哪里/发生崩溃时。
  • 你不能。您可以安装异常处理程序,但它们非常有限。您最好的选择可能是有一个调试模式,您可以在其中不断保存图像或记录信息。当应用程序崩溃时,希望最后写的内容包含您需要的信息。

标签: ios iphone swift crash screenshot


【解决方案1】:

AppDelegate:

func applicationWillTerminate(application: UIApplication) {
    //that methiod is called when app is going to crash
}

【讨论】:

  • 当我在 AppDelegate 的这个函数中编写上面的代码时,我得到'use of unresolved identifier 'view'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多