简体   繁体   中英

Microsoft.AppCenter.Crashes not detecting crashes on Xamarin.Forms iOS project

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

You can check if you meet the requirements as following shows:

-Your iOS project is set up in Xcode 11 or later on macOS version 10.14.4 or later.

-You're targeting devices running on iOS 9.0 or later.

-You're not using any other library that provides Crash Reporting functionality (only for App Center Crashes).

-If you are using CocoaPods to integrate App Center, you need CocoaPods version 1.10 or later.

App Center SDK Analytics and Crashes are compatible with Mac Catalyst via XCFramework or SwiftPM.

Here are more detail about appcenter crashed on ios https://learn.microsoft.com/en-us/appcenter/sdk/getting-started/ios

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM