我在调用TrackError之前注册了事件处理程序,但从未调用过它们。是的,事件发生了,因为错误出现在AppCenter中。
//On loading app
Crashes.SentErrorReport += (sender, args) => { System.Diagnostics.Process.GetCurrentProcess().Kill(); };
Crashes.FailedToSendErrorReport += (sender, args) => { System.Diagnostics.Process.GetCurrentProcess().Kill(); };
AppCenter.Start("{App secret here}" +
"android={App secret here}" +
"ios={App secret here}",
typeof(Analytics), typeof(Crashes));
//Elsewhere in the app
Crashes.TrackError(exception, comments, attachments);
遵循此文档:https://docs.microsoft.com/en-us/appcenter/sdk/crashes/xamarin
它们从未被调用,因为这两个事件处理程序不再在Page / Fragment / UIViewController的范围内。 (Xamarin.Forms中的页面,Xamarin.Android中的片段,Xamarin.iOS中的UIViewController)
您需要在新页面中重新分配事件处理程序。也许在所有其他页面继承的BasePage中定义它。
[App Center中处理的异常又称为错误(开发人员手动使用Crashes.trackError
报告的错误)不支持此功能。
该事件仅用于崩溃(导致应用程序退出未处理的异常)引起的。重新启动崩溃的进程后,也会调用这些事件。