I recently tried to implement Microsoft.AppCenter.Crashes to help track down crashes in my team's Xamarin.Forms app. However, when a crash happens on our iOS project, AppCenter never detects it. I've created the following function for setup and checking, which gets called near the start of our central project's App.xaml.cs App constructor:
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");
}
}
}
I've tested this code using the Crashes.GenerateTestCrash()
function, one of the crashes my team is trying to resolve, and a simple recursive function that calls itself forever. When run on iOS, our logs will always show the "AppCenter did not detect a crash in the last session" message, regardless of if a crash occurred. Any help determining what could be causing this would be appreciated.
Notes:
- The iOS project is always run without a debugger attached. I'm aware of the rule that crash reports will not be generated if iOS has a debugger attached
- This has been seen when built using both Debug and Release mode
- This code works as expected on our Android and UWP projects
- The iOS project always passes the
isEnabled
check - This is running AppCenter and AppCenter.Crashes version 4.5.0
- This is running on a 7th gen iPad on iOS 15.2.1
EDIT: Extra notes in response to a suggested answer:
- The Mac used to build the iOS project is running macOS 11.6.2
- Project is built using XCode 13.2.1
- The Xamarin Forms project is built in Visual Studio 2019 16.11.7, and sent to the connected mac via Visual Studio's "Pair to Mac" feature
- There are no other libraries used for crash reporting (the closest used is Serilog, which should only be handling logging)
- We do not use CocoaPods to integrate AppCenter