我开始利用Visual Studio App Center,并且他们有一种在应用程序重新启动时随每个崩溃报告上传文件附件的方法,例如:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<form action="/destroyImage" method="POST">
<div class="row">
<div class="col-4">
<div class="1st">
<button type="submit" class="close">
<span>×</span>
</button>
<img class="w-100" src="https://www.gettyimages.ie/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
</div>
</div>
<div class="col-4">
<div class="2nd">
<button type="submit" class="close">
<span>×</span>
</button>
<img class="w-100" src="https://www.gettyimages.ie/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
</div>
</div>
<div class="col-4">
<div class="3rd">
<button type="submit" class="close">
<span>×</span>
</button>
<img class="w-100" src="https://www.gettyimages.ie/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg">
</div>
</div>
</div>
</form>
这使我想到,在应用程序实际崩溃时拍摄屏幕截图不是很酷,这样我就可以更深入地了解导致崩溃的原因吗?然后,我可以将其保存到磁盘,并在应用程序重启时将其附加到错误报告中。我查了一下如何截取屏幕截图,当应用正常运行时,效果很好:
AppCenter.Start (Resources.GetString (Resource.String.appcenter_app_secret), typeof (Analytics), typeof (Crashes));
Crashes.GetErrorAttachments = (ErrorReport report) => {
var logs = new List<ErrorAttachmentLog> ();
var bytes = ContentHelper.GetBytes (AppCenterLoggingSink.ScreenShotFilePath);
if (bytes != null && bytes.Any ()) {
logs.Add (ErrorAttachmentLog.AttachmentWithBinary (bytes, AppCenterLoggingSink.SCREENSHOT_FILE_NAME, "image/jpeg"));
ContentHelper.Delete (AppCenterLoggingSink.ScreenShotFilePath);
}
return logs;
};
但是,如果我在应用崩溃时尝试执行此代码,则在调用“ var bitmap = view.DrawingCache;”时,它会自动失败。在控制台中看不到任何异常,如果我将它包装在try / catch中,则它永远也不会陷入困境。因此,有关应用程序处于崩溃状态和即将退出状态的某些信息,使得无法获取图形缓存。
我想知道如何解决此问题,以便在应用崩溃时可以截取屏幕截图?