Jelajahi Sumber

iOS: Fix SDL_EVENT_DROP_FILE lost on cold start from URL open

Jason Millard 1 bulan lalu
induk
melakukan
290f0c831f
1 mengubah file dengan 14 tambahan dan 3 penghapusan
  1. 14 3
      src/video/uikit/SDL_uikitappdelegate.m

+ 14 - 3
src/video/uikit/SDL_uikitappdelegate.m

@@ -352,6 +352,7 @@ API_AVAILABLE(ios(13.0))
 @implementation SDLUIKitSceneDelegate
 {
     UIWindow *launchWindow;
+    NSMutableArray<NSURL *> *launchURLs;
 }
 
 + (NSString *)getSceneDelegateClassName
@@ -411,15 +412,16 @@ API_AVAILABLE(ios(13.0))
     // Set working directory to resource path
     [[NSFileManager defaultManager] changeCurrentDirectoryPath:[bundle resourcePath]];
 
-    // Handle any connection options (like opening URLs)
+    launchURLs = [[NSMutableArray alloc] init];
+
     for (NSUserActivity *activity in connectionOptions.userActivities) {
         if (activity.webpageURL) {
-            [self handleURL:activity.webpageURL];
+            [launchURLs addObject:activity.webpageURL];
         }
     }
 
     for (UIOpenURLContext *urlContext in connectionOptions.URLContexts) {
-        [self handleURL:urlContext.URL];
+        [launchURLs addObject:urlContext.URL];
     }
 
     SDL_SetMainReady();
@@ -488,6 +490,7 @@ API_AVAILABLE(ios(13.0))
 - (void)postFinishLaunch
 {
     [self performSelector:@selector(hideLaunchScreen) withObject:nil afterDelay:0.0];
+    [self performSelector:@selector(processLaunchURLs) withObject:nil afterDelay:0.0];
 
     SDL_SetiOSEventPump(true);
     exit_status = SDL_CallMainFunction(forward_argc, forward_argv, forward_main);
@@ -499,6 +502,14 @@ API_AVAILABLE(ios(13.0))
     }
 }
 
+- (void)processLaunchURLs
+{
+    for (NSURL *url in launchURLs) {
+        [self handleURL:url];
+    }
+    launchURLs = nil;
+}
+
 - (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0))
 {
     // This doesn't appear to be called, but it needs to be implemented to signal that we support the UIScene life cycle