Skip to content

Commit 4b34d5f

Browse files
committed
fix(ios): restore compatibility for Ti.App._resumeRestart() (#13989)
* fix(ios): restore compatibility for Ti.App._resumeRestart() * chore: save session configuration, add warning for private API usage * chore: make sure to select the foreground/active scene, not only the first
1 parent 33cb788 commit 4b34d5f

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

Diff for: iphone/Classes/AppModule.m

+19-4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,23 @@ - (void)_resumeRestart:(id)unused
4848
#ifndef TI_USE_AUTOLAYOUT
4949
[TiLayoutQueue resetQueue];
5050
#endif
51+
52+
// Get the currently active scene
53+
UIScene *activeScene = nil;
54+
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
55+
if (scene.activationState == UISceneActivationStateForegroundActive) {
56+
activeScene = scene;
57+
break;
58+
}
59+
}
60+
61+
if (activeScene == nil) {
62+
NSLog(@"[ERROR] No active scene connected - this may lead to an undefined behavior");
63+
}
64+
5165
/* Begin backgrounding simulation */
52-
[appDelegate applicationWillResignActive:app];
53-
[appDelegate applicationDidEnterBackground:app];
66+
[appDelegate sceneWillResignActive:activeScene];
67+
[appDelegate sceneDidEnterBackground:activeScene];
5468
[appDelegate endBackgrounding];
5569
/* End backgrounding simulation */
5670

@@ -76,8 +90,9 @@ - (void)_resumeRestart:(id)unused
7690

7791
/* Begin foregrounding simulation */
7892
[appDelegate application:app didFinishLaunchingWithOptions:[appDelegate launchOptions]];
79-
[appDelegate applicationWillEnterForeground:app];
80-
[appDelegate applicationDidBecomeActive:app];
93+
[appDelegate scene:activeScene willConnectToSession:activeScene.session options:TiApp.app.connectionOptions];
94+
[appDelegate sceneWillEnterForeground:activeScene];
95+
[appDelegate sceneDidBecomeActive:activeScene];
8196
/* End foregrounding simulation */
8297
}
8398

Diff for: iphone/TitaniumKit/TitaniumKit/Sources/API/TiApp.h

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
KrollBridge *kjsBridge;
2727

2828
NSMutableDictionary *launchOptions;
29+
UISceneConnectionOptions *_connectionOptions;
2930
NSTimeInterval started;
3031

3132
int32_t networkActivityCount;
@@ -112,6 +113,13 @@
112113
*/
113114
@property (nonatomic, readonly) NSDictionary *localNotification;
114115

116+
/**
117+
Returns details for the last remote notification.
118+
119+
Dictionary containing details about remote notification, or _nil_.
120+
*/
121+
@property (nonatomic, readonly) UISceneConnectionOptions *connectionOptions;
122+
115123
/**
116124
Returns the application's root view controller.
117125
*/

Diff for: iphone/TitaniumKit/TitaniumKit/Sources/API/TiApp.m

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ @implementation TiApp
4848
@synthesize localNotification;
4949
@synthesize appBooted;
5050
@synthesize userAgent;
51+
@synthesize connectionOptions;
5152

5253
+ (TiApp *)app
5354
{
@@ -1062,6 +1063,7 @@ - (void)dealloc
10621063
RELEASE_TO_NIL(queuedBootEvents);
10631064
RELEASE_TO_NIL(_queuedApplicationSelectors);
10641065
RELEASE_TO_NIL(_applicationDelegates);
1066+
RELEASE_TO_NIL(_connectionOptions);
10651067

10661068
[super dealloc];
10671069
}
@@ -1110,6 +1112,12 @@ - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session op
11101112
// Initialize the launch options to be used by the client
11111113
launchOptions = [[NSMutableDictionary alloc] init];
11121114

1115+
// Retain connectionOptions for later use
1116+
if (_connectionOptions != connectionOptions) {
1117+
[_connectionOptions release]; // Release any existing object
1118+
_connectionOptions = [connectionOptions retain]; // Retain the new object
1119+
}
1120+
11131121
// If we have a APNS-UUID, assign it
11141122
NSString *apnsUUID = [[NSUserDefaults standardUserDefaults] stringForKey:@"APNSRemoteDeviceUUID"];
11151123
if (apnsUUID != nil) {

Diff for: iphone/TitaniumKit/TitaniumKit/Sources/API/TiRootViewController.m

+6-3
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,8 @@ - (void)shutdownUi:(id)arg
696696
if (![TiSharedConfig defaultConfig].debugEnabled) {
697697
return;
698698
}
699-
//FIRST DISMISS ALL MODAL WINDOWS
699+
700+
// Dismiss all currently opened windows
700701
UIViewController *topVC = [self topPresentedController];
701702
if (topVC != self) {
702703
UIViewController *presenter = [topVC presentingViewController];
@@ -706,7 +707,8 @@ - (void)shutdownUi:(id)arg
706707
}];
707708
return;
708709
}
709-
//At this point all modal stuff is done. Go ahead and clean up proxies.
710+
711+
// Clean up proxies.
710712
NSArray *modalCopy = [modalWindows copy];
711713
NSArray *windowCopy = [containedWindows copy];
712714

@@ -725,7 +727,8 @@ - (void)shutdownUi:(id)arg
725727
[windowCopy release];
726728
}
727729

728-
DebugLog(@"[INFO] UI SHUTDOWN COMPLETE. TRYING TO RESUME RESTART");
730+
DebugLog(@"[WARN] Calling the private `_restart()` API should not be done in production, as restarting an app is not a recommended native concept.");
731+
729732
if ([arg respondsToSelector:@selector(_resumeRestart:)]) {
730733
[arg performSelector:@selector(_resumeRestart:) withObject:nil];
731734
} else {

0 commit comments

Comments
 (0)