diff --git a/CHANGELOG.md b/CHANGELOG.md index 440cdc1344..f6312ecdfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ If you have conflicts, you can opt-out by adding the following to your `csproj`: ``` +### Fixes + +- Moved the binding to MAUI events for breadcrumb creation from `WillFinishLaunching` to `FinishedLaunching`. This delays the initial instantiation of `app`. ([#3057](https://github.com/getsentry/sentry-dotnet/pull/3057)) + ### Dependencies - Bump Java SDK from v7.1.0 to v7.2.0 ([#3049](https://github.com/getsentry/sentry-dotnet/pull/3049)) diff --git a/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs b/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs index f3d621b881..da2a569926 100644 --- a/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs +++ b/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs @@ -79,7 +79,7 @@ private static void RegisterMauiEventsBinder(this MauiAppBuilder builder) #if __IOS__ events.AddiOS(lifecycle => { - lifecycle.WillFinishLaunching((application, launchOptions) => + lifecycle.FinishedLaunching((application, launchOptions) => { // A bit of hackery here, because we can't mock UIKit.UIApplication in tests. var platformApplication = application != null! @@ -100,7 +100,7 @@ private static void RegisterMauiEventsBinder(this MauiAppBuilder builder) platformApplication?.HandleMauiEvents(bind: false); //According to https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623111-applicationwillterminate#discussion - //WillTerminate is called: in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason. + //WillTerminate is called: in situations where the app is running in the background (not suspended) and the system needs to terminate it for some reason. SentryMauiEventProcessor.InForeground = false; }); diff --git a/test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.Cocoa.cs b/test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.Cocoa.cs index 594300c02c..716d613185 100644 --- a/test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.Cocoa.cs +++ b/test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.Cocoa.cs @@ -27,8 +27,8 @@ public void UseSentry_BindsToApplicationStartupEvent_iOS() // Act var lifecycleEventService = app.Services.GetRequiredService(); - lifecycleEventService.InvokeEvents - (nameof(iOSLifecycle.WillFinishLaunching), del => + lifecycleEventService.InvokeEvents + (nameof(iOSLifecycle.FinishedLaunching), del => del.Invoke(null!, launchOptions)); // Assert