diff --git a/packages/core/application/application.d.ts b/packages/core/application/application.d.ts index e5c2eec0c7..a305a88838 100644 --- a/packages/core/application/application.d.ts +++ b/packages/core/application/application.d.ts @@ -265,6 +265,12 @@ export class iOSApplication extends ApplicationCommon { * Get the current one or set a custom one. */ sceneDelegate: UIWindowSceneDelegate; + + /** + * Flag to be set when the launch event should be delayed until the application has become active. + * This is useful when you want to process notifications or data in the background without creating the UI. + */ + shouldDelayLaunchEvent: boolean; } export const VALID_FONT_SCALES: number[]; diff --git a/packages/core/application/application.ios.ts b/packages/core/application/application.ios.ts index 0a581e5ffc..df76b1f827 100644 --- a/packages/core/application/application.ios.ts +++ b/packages/core/application/application.ios.ts @@ -9,6 +9,7 @@ import { ios as iosUtils, dataSerialize } from '../utils/native-helper'; import { ApplicationCommon, initializeSdkVersionClass, SceneEvents } from './application-common'; import { ApplicationEventData, SceneEventData } from './application-interfaces'; import { Observable } from '../data/observable'; +import type { iOSApplication as IiOSApplication } from './application'; import { Trace } from '../trace'; import { AccessibilityServiceEnabledPropName, @@ -256,10 +257,11 @@ class SceneDelegate extends UIResponder implements UIWindowSceneDelegate { // ensure available globally global.SceneDelegate = SceneDelegate; -export class iOSApplication extends ApplicationCommon { +export class iOSApplication extends ApplicationCommon implements IiOSApplication { private _delegate: UIApplicationDelegate; private _delegateHandlers = new Map>(); private _rootView: View; + private launchEventCalled = false; private _sceneDelegate: UIWindowSceneDelegate; private _windowSceneMap = new Map(); private _primaryScene: UIWindowScene | null = null; @@ -271,6 +273,8 @@ export class iOSApplication extends ApplicationCommon { displayedLinkTarget: CADisplayLinkTarget; displayedLink: CADisplayLink; + shouldDelayLaunchEvent = false; + /** * @internal - should not be constructed by the user. */ @@ -585,6 +589,7 @@ export class iOSApplication extends ApplicationCommon { } private notifyAppStarted(notification?: NSNotification) { + this.launchEventCalled = true; const root = this.notifyLaunch({ ios: notification?.userInfo?.objectForKey('UIApplicationLaunchOptionsLocalNotificationKey') ?? null, }); @@ -693,7 +698,10 @@ export class iOSApplication extends ApplicationCommon { this.window.backgroundColor = SDK_VERSION <= 12 || !UIColor.systemBackgroundColor ? UIColor.whiteColor : UIColor.systemBackgroundColor; } - this.notifyAppStarted(notification); + this.launchEventCalled = false; + if (!this.shouldDelayLaunchEvent) { + this.notifyAppStarted(); + } } else { // Scene-based app - window creation will happen in scene delegate } @@ -701,6 +709,9 @@ export class iOSApplication extends ApplicationCommon { @profile private didBecomeActive(notification: NSNotification) { + if (!this.launchEventCalled) { + this.notifyAppStarted(notification); + } const additionalData = { ios: UIApplication.sharedApplication, };