我最近尝试实现 Microsoft.AppCenter.Crashes 来帮助跟踪我团队的 Xamarin.Forms 应用程序中的崩溃情况。然而,当我们的 iOS 项目发生崩溃时,AppCenter 永远不会检测到它。我创建了以下用于设置和检查的函数,该函数在我们的中心项目的 App.xaml.cs 应用构造函数开始附近被调用:
private async Task CheckForPreviousCrash()
{
//Setup AppCenter
await Xamarin.Forms.Device.InvokeOnMainThreadAsync(() =>
{
//Keys changed in StackOverflow post for security reasons.
AppCenter.Start("ios=########-####-####-####-############;android=########-####-####-####-############;uwp=########-####-####-####-############", typeof(Crashes));
AppCenter.IsNetworkRequestsAllowed = false; //Prevents sending user data to Microsoft. Required by company
});
//Make sure AppCenter is working
bool isEnabled = await Crashes.IsEnabledAsync();
if (!isEnabled)
{
_logger.LogError("AppCenter could not be started");
}
else
{
//Check for memory leak warnings
bool memoryIssue = await Crashes.HasReceivedMemoryWarningInLastSessionAsync();
if (memoryIssue)
{
_logger.LogError("AppCenter detected a memory warning in the last session");
}
//Check for crash info
bool crashed = await Crashes.HasCrashedInLastSessionAsync();
if (crashed)
{
var report = await Crashes.GetLastSessionCrashReportAsync();
_logger.LogCrashReport(report);
}
//If AppCenter detected no issues in the last session, log an "all clear" message
if (!memoryIssue && !crashed)
{
_logger.LogInformation("AppCenter did not detect a crash in the last session");
}
}
}
我已经使用
Crashes.GenerateTestCrash()
函数测试了这段代码,这是我的团队正在尝试解决的崩溃之一,也是一个永远调用自身的简单递归函数。在 iOS 上运行时,我们的日志将始终显示“AppCenter 在上次会话中未检测到崩溃”消息,无论是否发生崩溃。任何帮助确定可能导致此问题的原因将不胜感激。
备注:
isEnabled
用于构建 iOS 项目的 Mac 运行的是 macOS 11.6.2
-您的 iOS 项目是在 macOS 版本 10.14.4 或更高版本上的 Xcode 11 或更高版本中设置的。
-您的目标设备运行在 iOS 9.0 或更高版本上。
-您没有使用任何其他提供崩溃报告功能的库(仅适用于应用程序中心崩溃)。
-如果您使用 CocoaPods 集成 App Center,则需要 CocoaPods 1.10 或更高版本。
App Center SDK 分析和崩溃通过 XCFramework 或 SwiftPM 与 Mac Catalyst 兼容。
以下是有关 iOS 上应用程序中心崩溃的更多详细信息
https://learn.microsoft.com/en-us/appcenter/sdk/getting-started/ios