@nativescript/core 9.0.0-next-11-01-2025-18992401913 → 9.0.0-next-11-04-2025-19054296432

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,8 @@ import { isEmbedded } from '../ui/embedding';
3
3
  import { IOSHelper } from '../ui/core/view/view-helper';
4
4
  import { getWindow } from '../utils/native-helper';
5
5
  import { SDK_VERSION } from '../utils/constants';
6
- import { ios as iosUtils } from '../utils/native-helper';
7
- import { ApplicationCommon, initializeSdkVersionClass } from './application-common';
6
+ import { ios as iosUtils, dataSerialize } from '../utils/native-helper';
7
+ import { ApplicationCommon, initializeSdkVersionClass, SceneEvents } from './application-common';
8
8
  import { Observable } from '../data/observable';
9
9
  import { Trace } from '../trace';
10
10
  import { AccessibilityServiceEnabledPropName, CommonA11YServiceEnabledObservable, SharedA11YObservable, a11yServiceClasses, a11yServiceDisabledClass, a11yServiceEnabledClass, fontScaleCategoryClasses, fontScaleExtraLargeCategoryClass, fontScaleExtraSmallCategoryClass, fontScaleMediumCategoryClass, getCurrentA11YServiceClass, getCurrentFontScaleCategory, getCurrentFontScaleClass, getFontScaleCssClasses, setCurrentA11YServiceClass, setCurrentFontScaleCategory, setCurrentFontScaleClass, setFontScaleCssClasses, FontScaleCategory, getClosestValidFontScale, VALID_FONT_SCALES, setFontScale, getFontScale, setInitFontScale, getFontScaleCategory, setInitAccessibilityCssHelper, notifyAccessibilityFocusState, AccessibilityLiveRegion, AccessibilityRole, AccessibilityState, AccessibilityTrait, isA11yEnabled, setA11yEnabled, enforceArray, } from '../accessibility/accessibility-common';
@@ -40,6 +40,28 @@ var CADisplayLinkTarget = /** @class */ (function (_super) {
40
40
  };
41
41
  return CADisplayLinkTarget;
42
42
  }(NSObject));
43
+ /**
44
+ * Detect if the app supports scenes.
45
+ * When an app configures UIApplicationSceneManifest in Info.plist
46
+ * it will use scene lifecycle management.
47
+ */
48
+ let sceneManifest;
49
+ function supportsScenes() {
50
+ if (SDK_VERSION < 13) {
51
+ return false;
52
+ }
53
+ if (typeof sceneManifest === 'undefined') {
54
+ // Check if scene manifest exists in Info.plist
55
+ sceneManifest = NSBundle.mainBundle.objectForInfoDictionaryKey('UIApplicationSceneManifest');
56
+ }
57
+ return !!sceneManifest;
58
+ }
59
+ function supportsMultipleScenes() {
60
+ if (SDK_VERSION < 13) {
61
+ return false;
62
+ }
63
+ return UIApplication.sharedApplication?.supportsMultipleScenes;
64
+ }
43
65
  var Responder = /** @class */ (function (_super) {
44
66
  __extends(Responder, _super);
45
67
  function Responder() {
@@ -58,6 +80,109 @@ var Responder = /** @class */ (function (_super) {
58
80
  Responder.ObjCProtocols = [UIApplicationDelegate];
59
81
  return Responder;
60
82
  }(UIResponder));
83
+ if (supportsScenes()) {
84
+ /**
85
+ * This method is called when a new scene session is being created.
86
+ * Important: When this method is implemented, the app assumes scene-based lifecycle management.
87
+ * Detected by the Info.plist existence 'UIApplicationSceneManifest'.
88
+ * If this method is implemented when there is no manifest defined,
89
+ * the app will boot to a white screen.
90
+ */
91
+ Responder.prototype.applicationConfigurationForConnectingSceneSessionOptions = function (application, connectingSceneSession, options) {
92
+ const config = UISceneConfiguration.configurationWithNameSessionRole('Default Configuration', connectingSceneSession.role);
93
+ config.sceneClass = UIWindowScene;
94
+ config.delegateClass = SceneDelegate;
95
+ return config;
96
+ };
97
+ // scene session destruction handling
98
+ Responder.prototype.applicationDidDiscardSceneSessions = function (application, sceneSessions) {
99
+ // Note: we could emit an event here if needed
100
+ // console.log('Scene sessions discarded:', sceneSessions.count);
101
+ };
102
+ }
103
+ var SceneDelegate = /** @class */ (function (_super) {
104
+ __extends(SceneDelegate, _super);
105
+ function SceneDelegate() {
106
+ return _super !== null && _super.apply(this, arguments) || this;
107
+ }
108
+ Object.defineProperty(SceneDelegate.prototype, "window", {
109
+ get: function () {
110
+ return this._window;
111
+ },
112
+ set: function (value) {
113
+ this._window = value;
114
+ },
115
+ enumerable: true,
116
+ configurable: true
117
+ });
118
+ SceneDelegate.prototype.sceneWillConnectToSessionOptions = function (scene, session, connectionOptions) {
119
+ if (Trace.isEnabled()) {
120
+ Trace.write("SceneDelegate.sceneWillConnectToSessionOptions called with role: ".concat(session.role), Trace.categories.NativeLifecycle);
121
+ }
122
+ if (!(scene instanceof UIWindowScene)) {
123
+ // Scene is not a UIWindowScene, ignoring
124
+ return;
125
+ }
126
+ this._scene = scene;
127
+ // Create window for this scene
128
+ this._window = UIWindow.alloc().initWithWindowScene(scene);
129
+ // Store the window scene for this window
130
+ Application.ios._setWindowForScene(this._window, scene);
131
+ // Set up the window content
132
+ Application.ios._setupWindowForScene(this._window, scene);
133
+ // Notify that scene will connect
134
+ Application.ios.notify({
135
+ eventName: SceneEvents.sceneWillConnect,
136
+ object: Application.ios,
137
+ scene: scene,
138
+ window: this._window,
139
+ connectionOptions: connectionOptions,
140
+ });
141
+ if (scene === Application.ios.getPrimaryScene()) {
142
+ // primary scene, activate right away
143
+ this._window.makeKeyAndVisible();
144
+ }
145
+ else {
146
+ // For secondary scenes, emit an event to allow developers to set up custom content for the window
147
+ Application.ios.notify({
148
+ eventName: SceneEvents.sceneContentSetup,
149
+ object: Application.ios,
150
+ scene: scene,
151
+ window: this._window,
152
+ connectionOptions: connectionOptions,
153
+ });
154
+ }
155
+ // If this is the first scene, trigger app startup
156
+ if (!Application.ios.getPrimaryScene()) {
157
+ Application.ios._notifySceneAppStarted();
158
+ }
159
+ };
160
+ SceneDelegate.prototype.sceneDidBecomeActive = function (scene) {
161
+ // This will be handled by the notification observer in iOSApplication
162
+ // The notification system will automatically trigger sceneDidActivate
163
+ };
164
+ SceneDelegate.prototype.sceneWillResignActive = function (scene) {
165
+ // Notify that scene will resign active
166
+ Application.ios.notify({
167
+ eventName: SceneEvents.sceneWillResignActive,
168
+ object: Application.ios,
169
+ scene: scene,
170
+ });
171
+ };
172
+ SceneDelegate.prototype.sceneWillEnterForeground = function (scene) {
173
+ // This will be handled by the notification observer in iOSApplication
174
+ };
175
+ SceneDelegate.prototype.sceneDidEnterBackground = function (scene) {
176
+ // This will be handled by the notification observer in iOSApplication
177
+ };
178
+ SceneDelegate.prototype.sceneDidDisconnect = function (scene) {
179
+ // This will be handled by the notification observer in iOSApplication
180
+ };
181
+ SceneDelegate.ObjCProtocols = [UIWindowSceneDelegate];
182
+ return SceneDelegate;
183
+ }(UIResponder));
184
+ // ensure available globally
185
+ global.SceneDelegate = SceneDelegate;
61
186
  export class iOSApplication extends ApplicationCommon {
62
187
  /**
63
188
  * @internal - should not be constructed by the user.
@@ -65,6 +190,9 @@ export class iOSApplication extends ApplicationCommon {
65
190
  constructor() {
66
191
  super();
67
192
  this._delegateHandlers = new Map();
193
+ this._windowSceneMap = new Map();
194
+ this._primaryScene = null;
195
+ this._openedScenesById = new Map();
68
196
  this.displayedOnce = false;
69
197
  this.addNotificationObserver(UIApplicationDidFinishLaunchingNotification, this.didFinishLaunchingWithOptions.bind(this));
70
198
  this.addNotificationObserver(UIApplicationDidBecomeActiveNotification, this.didBecomeActive.bind(this));
@@ -72,6 +200,14 @@ export class iOSApplication extends ApplicationCommon {
72
200
  this.addNotificationObserver(UIApplicationWillTerminateNotification, this.willTerminate.bind(this));
73
201
  this.addNotificationObserver(UIApplicationDidReceiveMemoryWarningNotification, this.didReceiveMemoryWarning.bind(this));
74
202
  this.addNotificationObserver(UIApplicationDidChangeStatusBarOrientationNotification, this.didChangeStatusBarOrientation.bind(this));
203
+ // Add scene lifecycle notification observers only if scenes are supported
204
+ if (this.supportsScenes()) {
205
+ this.addNotificationObserver('UISceneWillConnectNotification', this.sceneWillConnect.bind(this));
206
+ this.addNotificationObserver('UISceneDidActivateNotification', this.sceneDidActivate.bind(this));
207
+ this.addNotificationObserver('UISceneWillEnterForegroundNotification', this.sceneWillEnterForeground.bind(this));
208
+ this.addNotificationObserver('UISceneDidEnterBackgroundNotification', this.sceneDidEnterBackground.bind(this));
209
+ this.addNotificationObserver('UISceneDidDisconnectNotification', this.sceneDidDisconnect.bind(this));
210
+ }
75
211
  }
76
212
  getRootView() {
77
213
  return this._rootView;
@@ -303,6 +439,10 @@ export class iOSApplication extends ApplicationCommon {
303
439
  setiOSWindow(this.window);
304
440
  }
305
441
  }
442
+ // Public method for scene-based app startup
443
+ _notifySceneAppStarted() {
444
+ this.notifyAppStarted();
445
+ }
306
446
  _onLivesync(context) {
307
447
  // Handle application root module
308
448
  const isAppRootModuleChanged = context && context.path && context.path.includes(this.getMainEntry().moduleName) && context.type !== 'style';
@@ -358,16 +498,23 @@ export class iOSApplication extends ApplicationCommon {
358
498
  }
359
499
  }
360
500
  this.setMaxRefreshRate();
361
- // ensures window is assigned to proper window scene
362
- setiOSWindow(this.window);
363
- if (!getiOSWindow()) {
364
- // if still no window, create one
365
- setiOSWindow(UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds));
501
+ // Only set up window if NOT using scene-based lifecycle
502
+ if (!this.supportsScenes()) {
503
+ // Traditional single-window app setup
504
+ // ensures window is assigned to proper window scene
505
+ setiOSWindow(this.window);
506
+ if (!getiOSWindow()) {
507
+ // if still no window, create one
508
+ setiOSWindow(UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds));
509
+ }
510
+ if (!__VISIONOS__) {
511
+ this.window.backgroundColor = SDK_VERSION <= 12 || !UIColor.systemBackgroundColor ? UIColor.whiteColor : UIColor.systemBackgroundColor;
512
+ }
513
+ this.notifyAppStarted(notification);
366
514
  }
367
- if (!__VISIONOS__) {
368
- this.window.backgroundColor = SDK_VERSION <= 12 || !UIColor.systemBackgroundColor ? UIColor.whiteColor : UIColor.systemBackgroundColor;
515
+ else {
516
+ // Scene-based app - window creation will happen in scene delegate
369
517
  }
370
- this.notifyAppStarted(notification);
371
518
  }
372
519
  didBecomeActive(notification) {
373
520
  const additionalData = {
@@ -414,6 +561,431 @@ export class iOSApplication extends ApplicationCommon {
414
561
  const newOrientation = this.getOrientationValue(statusBarOrientation);
415
562
  this.setOrientation(newOrientation);
416
563
  }
564
+ // Scene lifecycle notification handlers
565
+ sceneWillConnect(notification) {
566
+ const scene = notification.object;
567
+ if (!scene || !(scene instanceof UIWindowScene)) {
568
+ return;
569
+ }
570
+ // Store as primary scene if it's the first one
571
+ if (!this._primaryScene) {
572
+ this._primaryScene = scene;
573
+ }
574
+ this.notify({
575
+ eventName: SceneEvents.sceneWillConnect,
576
+ object: this,
577
+ scene: scene,
578
+ userInfo: notification.userInfo,
579
+ });
580
+ }
581
+ sceneDidActivate(notification) {
582
+ const scene = notification.object;
583
+ this.notify({
584
+ eventName: SceneEvents.sceneDidActivate,
585
+ object: this,
586
+ scene: scene,
587
+ });
588
+ // If this is the primary scene, trigger traditional app lifecycle
589
+ if (scene === this._primaryScene) {
590
+ const additionalData = {
591
+ ios: UIApplication.sharedApplication,
592
+ scene: scene,
593
+ };
594
+ this.setInBackground(false, additionalData);
595
+ this.setSuspended(false, additionalData);
596
+ if (this._rootView && !this._rootView.isLoaded) {
597
+ this._rootView.callLoaded();
598
+ }
599
+ }
600
+ }
601
+ sceneWillEnterForeground(notification) {
602
+ const scene = notification.object;
603
+ this.notify({
604
+ eventName: SceneEvents.sceneWillEnterForeground,
605
+ object: this,
606
+ scene: scene,
607
+ });
608
+ }
609
+ sceneDidEnterBackground(notification) {
610
+ const scene = notification.object;
611
+ this.notify({
612
+ eventName: SceneEvents.sceneDidEnterBackground,
613
+ object: this,
614
+ scene: scene,
615
+ });
616
+ // If this is the primary scene, trigger traditional app lifecycle
617
+ if (scene === this._primaryScene) {
618
+ const additionalData = {
619
+ ios: UIApplication.sharedApplication,
620
+ scene: scene,
621
+ };
622
+ this.setInBackground(true, additionalData);
623
+ this.setSuspended(true, additionalData);
624
+ if (this._rootView && this._rootView.isLoaded) {
625
+ this._rootView.callUnloaded();
626
+ }
627
+ }
628
+ }
629
+ sceneDidDisconnect(notification) {
630
+ const scene = notification.object;
631
+ this._removeWindowForScene(scene);
632
+ // If primary scene disconnected, clear it
633
+ if (scene === this._primaryScene) {
634
+ this._primaryScene = null;
635
+ }
636
+ if (this._primaryScene) {
637
+ if (SDK_VERSION >= 17) {
638
+ const request = UISceneSessionActivationRequest.requestWithSession(this._primaryScene.session);
639
+ UIApplication.sharedApplication.activateSceneSessionForRequestErrorHandler(request, (err) => {
640
+ if (err) {
641
+ console.log('Failed to activate primary scene:', err.localizedDescription);
642
+ }
643
+ });
644
+ }
645
+ else {
646
+ UIApplication.sharedApplication.requestSceneSessionActivationUserActivityOptionsErrorHandler(this._primaryScene.session, null, null, (err) => {
647
+ if (err) {
648
+ console.log('Failed to activate primary scene (legacy):', err.localizedDescription);
649
+ }
650
+ });
651
+ }
652
+ }
653
+ this.notify({
654
+ eventName: SceneEvents.sceneDidDisconnect,
655
+ object: this,
656
+ scene: scene,
657
+ });
658
+ }
659
+ // Scene management helper methods
660
+ _setWindowForScene(window, scene) {
661
+ this._windowSceneMap.set(scene, window);
662
+ }
663
+ _removeWindowForScene(scene) {
664
+ this._windowSceneMap.delete(scene);
665
+ // also untrack opened scene id
666
+ try {
667
+ const s = scene;
668
+ if (s && s.session) {
669
+ const id = this._getSceneId(s);
670
+ this._openedScenesById.delete(id);
671
+ }
672
+ }
673
+ catch { }
674
+ }
675
+ _getWindowForScene(scene) {
676
+ return this._windowSceneMap.get(scene);
677
+ }
678
+ _setupWindowForScene(window, scene) {
679
+ if (!window) {
680
+ return;
681
+ }
682
+ // track opened scene
683
+ try {
684
+ const id = this._getSceneId(scene);
685
+ this._openedScenesById.set(id, scene);
686
+ }
687
+ catch { }
688
+ // Set up window background
689
+ if (!__VISIONOS__) {
690
+ window.backgroundColor = SDK_VERSION <= 12 || !UIColor.systemBackgroundColor ? UIColor.whiteColor : UIColor.systemBackgroundColor;
691
+ }
692
+ // If this is the primary scene, set up the main application content
693
+ if (scene === this._primaryScene || !this._primaryScene) {
694
+ this._primaryScene = scene;
695
+ if (!getiOSWindow()) {
696
+ setiOSWindow(window);
697
+ }
698
+ // Set up the window content for the primary scene
699
+ this.setWindowContent();
700
+ }
701
+ }
702
+ get sceneDelegate() {
703
+ if (!this._sceneDelegate) {
704
+ this._sceneDelegate = SceneDelegate.new();
705
+ }
706
+ return this._sceneDelegate;
707
+ }
708
+ set sceneDelegate(value) {
709
+ this._sceneDelegate = value;
710
+ }
711
+ /**
712
+ * Multi-window support
713
+ */
714
+ /**
715
+ * Opens a new window with the specified data.
716
+ * @param data The data to pass to the new window.
717
+ */
718
+ openWindow(data) {
719
+ if (!supportsMultipleScenes()) {
720
+ console.log('Cannot create a new scene - not supported on this device.');
721
+ return;
722
+ }
723
+ try {
724
+ const app = UIApplication.sharedApplication;
725
+ // iOS 17+
726
+ if (SDK_VERSION >= 17) {
727
+ // Create a new scene activation request with proper role
728
+ let request;
729
+ try {
730
+ // Use the correct factory method to create request with role
731
+ // Based on the type definitions, this is the proper way
732
+ request = UISceneSessionActivationRequest.requestWithRole(UIWindowSceneSessionRoleApplication);
733
+ // Note: may be useful to allow user defined activity type through optional string typed data in future
734
+ const activity = NSUserActivity.alloc().initWithActivityType(`${NSBundle.mainBundle.bundleIdentifier}.scene`);
735
+ activity.userInfo = dataSerialize(data);
736
+ request.userActivity = activity;
737
+ // Set proper options with requesting scene
738
+ const options = UISceneActivationRequestOptions.new();
739
+ // Note: explore secondary windows spawning other windows
740
+ // and if this context needs to change in those cases
741
+ const mainWindow = Application.ios.getPrimaryWindow();
742
+ options.requestingScene = mainWindow?.windowScene;
743
+ /**
744
+ * Note: This does not work in testing but worth exploring further sometime
745
+ * regarding the size/dimensions of opened secondary windows.
746
+ * The initial size is ultimately determined by the system
747
+ * based on available space and user context.
748
+ */
749
+ // Get the size restrictions from the window scene
750
+ // const sizeRestrictions = (options.requestingScene as UIWindowScene).sizeRestrictions;
751
+ // // Set your minimum and maximum dimensions
752
+ // sizeRestrictions.minimumSize = CGSizeMake(320, 400);
753
+ // sizeRestrictions.maximumSize = CGSizeMake(600, 800);
754
+ request.options = options;
755
+ }
756
+ catch (roleError) {
757
+ console.log('Error creating request:', roleError);
758
+ return;
759
+ }
760
+ app.activateSceneSessionForRequestErrorHandler(request, (error) => {
761
+ if (error) {
762
+ console.log('Error creating new scene (iOS 17+):', error);
763
+ // Log additional debugging info
764
+ if (error.userInfo) {
765
+ console.error(`Error userInfo: ${error.userInfo.description}`);
766
+ }
767
+ // Handle specific error types
768
+ if (error.localizedDescription.includes('role') && error.localizedDescription.includes('nil')) {
769
+ this.createSceneWithLegacyAPI(data);
770
+ }
771
+ else if (error.domain === 'FBSWorkspaceErrorDomain' && error.code === 2) {
772
+ this.createSceneWithLegacyAPI(data);
773
+ }
774
+ }
775
+ });
776
+ }
777
+ // iOS 13-16 - Use the legacy requestSceneSessionActivationUserActivityOptionsErrorHandler method
778
+ else if (SDK_VERSION >= 13 && SDK_VERSION < 17) {
779
+ app.requestSceneSessionActivationUserActivityOptionsErrorHandler(null, // session
780
+ null, // userActivity
781
+ null, // options
782
+ (error) => {
783
+ if (error) {
784
+ console.log('Error creating new scene (legacy):', error);
785
+ }
786
+ });
787
+ }
788
+ // Fallback for older iOS versions or unsupported configurations
789
+ else {
790
+ console.log('Neither new nor legacy scene activation methods are available');
791
+ }
792
+ }
793
+ catch (error) {
794
+ console.error('Error requesting new scene:', error);
795
+ }
796
+ }
797
+ /**
798
+ * Closes a secondary window/scene.
799
+ * Usage examples:
800
+ * - Application.ios.closeWindow() // best-effort close of a non-primary scene
801
+ * - Application.ios.closeWindow(button) // from a tap handler within the scene
802
+ * - Application.ios.closeWindow(window)
803
+ * - Application.ios.closeWindow(scene)
804
+ * - Application.ios.closeWindow('scene-id')
805
+ */
806
+ closeWindow(target) {
807
+ if (!__APPLE__) {
808
+ return;
809
+ }
810
+ try {
811
+ const scene = this._resolveScene(target);
812
+ if (!scene) {
813
+ console.log('closeWindow: No scene resolved for target');
814
+ return;
815
+ }
816
+ // Don't allow closing the primary scene
817
+ if (scene === this._primaryScene) {
818
+ console.log('closeWindow: Refusing to close the primary scene');
819
+ return;
820
+ }
821
+ const session = scene.session;
822
+ if (!session) {
823
+ console.log('closeWindow: Scene has no session to destroy');
824
+ return;
825
+ }
826
+ const app = UIApplication.sharedApplication;
827
+ if (app.requestSceneSessionDestructionOptionsErrorHandler) {
828
+ app.requestSceneSessionDestructionOptionsErrorHandler(session, null, (error) => {
829
+ if (error) {
830
+ console.log('closeWindow: destruction error', error);
831
+ }
832
+ else {
833
+ // clean up tracked id
834
+ const id = this._getSceneId(scene);
835
+ this._openedScenesById.delete(id);
836
+ }
837
+ });
838
+ }
839
+ else {
840
+ console.info('closeWindow: Scene destruction API not available on this iOS version');
841
+ }
842
+ }
843
+ catch (err) {
844
+ console.log('closeWindow: Unexpected error', err);
845
+ }
846
+ }
847
+ getAllWindows() {
848
+ return Array.from(this._windowSceneMap.values());
849
+ }
850
+ getAllScenes() {
851
+ return Array.from(this._windowSceneMap.keys());
852
+ }
853
+ getWindowScenes() {
854
+ return this.getAllScenes().filter((scene) => scene instanceof UIWindowScene);
855
+ }
856
+ getPrimaryWindow() {
857
+ if (this._primaryScene) {
858
+ return this._getWindowForScene(this._primaryScene) || getiOSWindow();
859
+ }
860
+ return getiOSWindow();
861
+ }
862
+ getPrimaryScene() {
863
+ return this._primaryScene;
864
+ }
865
+ // Scene lifecycle management
866
+ supportsScenes() {
867
+ return supportsScenes();
868
+ }
869
+ supportsMultipleScenes() {
870
+ return supportsMultipleScenes();
871
+ }
872
+ isUsingSceneLifecycle() {
873
+ return this.supportsScenes() && this._windowSceneMap.size > 0;
874
+ }
875
+ // Call this to set up scene-based configuration
876
+ configureForScenes() {
877
+ if (!this.supportsScenes()) {
878
+ console.warn('Scene-based lifecycle is only supported on iOS 13+ iPad or visionOS with multi-scene enabled apps.');
879
+ return;
880
+ }
881
+ // Additional scene configuration can be added here
882
+ // For now, the notification observers are already set up in the constructor
883
+ }
884
+ // Stable scene id for lookups
885
+ _getSceneId(scene) {
886
+ try {
887
+ if (!scene) {
888
+ return 'Unknown';
889
+ }
890
+ // Prefer session persistentIdentifier when available (stable across lifetime)
891
+ const session = scene.session;
892
+ const persistentId = session && session.persistentIdentifier;
893
+ if (persistentId) {
894
+ return `${persistentId}`;
895
+ }
896
+ // Fallbacks
897
+ if (scene.hash != null) {
898
+ return `${scene.hash}`;
899
+ }
900
+ const desc = scene.description;
901
+ if (desc) {
902
+ return `${desc}`;
903
+ }
904
+ }
905
+ catch (err) {
906
+ // ignore
907
+ }
908
+ return 'Unknown';
909
+ }
910
+ // Resolve a UIWindowScene from various input types
911
+ _resolveScene(target) {
912
+ if (!__APPLE__) {
913
+ return null;
914
+ }
915
+ if (!target) {
916
+ // Try to pick a non-primary foreground active scene, else last known scene
917
+ const scenes = this.getWindowScenes?.() || [];
918
+ const nonPrimary = scenes.filter((s) => s !== this._primaryScene);
919
+ return nonPrimary[0] || scenes[0] || null;
920
+ }
921
+ // If a View was passed, derive its window.scene
922
+ if (target && typeof target === 'object') {
923
+ // UIWindowScene
924
+ if (target.session && target.activationState !== undefined) {
925
+ return target;
926
+ }
927
+ // UIWindow
928
+ if (target.windowScene) {
929
+ return target.windowScene;
930
+ }
931
+ // NativeScript View
932
+ if (target?.nativeViewProtected) {
933
+ const uiView = target.nativeViewProtected;
934
+ const win = uiView?.window;
935
+ return win?.windowScene || null;
936
+ }
937
+ }
938
+ // String id lookup
939
+ if (typeof target === 'string') {
940
+ if (this._openedScenesById.has(target)) {
941
+ return this._openedScenesById.get(target);
942
+ }
943
+ // Try matching by persistentIdentifier or hash among known scenes
944
+ const scenes = this.getWindowScenes?.() || [];
945
+ for (const s of scenes) {
946
+ const sid = this._getSceneId(s);
947
+ if (sid === target) {
948
+ return s;
949
+ }
950
+ }
951
+ }
952
+ return null;
953
+ }
954
+ createSceneWithLegacyAPI(data) {
955
+ const windowScene = this.window?.windowScene;
956
+ if (!windowScene) {
957
+ return;
958
+ }
959
+ // Create user activity for the new scene
960
+ const userActivity = NSUserActivity.alloc().initWithActivityType(`${NSBundle.mainBundle.bundleIdentifier}.scene`);
961
+ userActivity.userInfo = dataSerialize(data);
962
+ // Use the legacy API
963
+ const options = UISceneActivationRequestOptions.new();
964
+ options.requestingScene = windowScene;
965
+ UIApplication.sharedApplication.requestSceneSessionActivationUserActivityOptionsErrorHandler(null, // session - null for new scene
966
+ userActivity, options, (error) => {
967
+ if (error) {
968
+ console.error(`Legacy scene API failed: ${error.localizedDescription}`);
969
+ }
970
+ });
971
+ }
972
+ /**
973
+ * Creates a simple view controller with a NativeScript view for a scene window.
974
+ * @param window The UIWindow to set content for
975
+ * @param view The NativeScript View to set as root content
976
+ */
977
+ setWindowRootView(window, view) {
978
+ if (!window || !view) {
979
+ return;
980
+ }
981
+ if (view.ios) {
982
+ window.rootViewController = view.viewController;
983
+ window.makeKeyAndVisible();
984
+ }
985
+ else {
986
+ console.warn('View does not have a native iOS implementation');
987
+ }
988
+ }
417
989
  get ios() {
418
990
  // ensures Application.ios is defined when running on iOS
419
991
  return this;