Przeglądaj źródła

Add support for new UIScene APIs (#304)

Iulian Onofrei 7 lat temu
rodzic
commit
adf2fc56e8
2 zmienionych plików z 34 dodań i 0 usunięć
  1. 8 0
      Classes/FLEXManager.h
  2. 26 0
      Classes/Manager/FLEXManager.m

+ 8 - 0
Classes/FLEXManager.h

@@ -9,6 +9,10 @@
 #import <Foundation/Foundation.h>
 #import <UIKit/UIKit.h>
 
+#if !FLEX_AT_LEAST_IOS13_SDK
+@class UIWindowScene;
+#endif
+
 typedef UIViewController *(^FLEXCustomContentViewerFuture)(NSData *data);
 
 @interface FLEXManager : NSObject
@@ -21,6 +25,10 @@ typedef UIViewController *(^FLEXCustomContentViewerFuture)(NSData *data);
 - (void)hideExplorer;
 - (void)toggleExplorer;
 
+/// Use this to present the explorer in a specific scene when the one
+/// it chooses by default is not the one you wish to display it in.
+- (void)showExplorerFromScene:(UIWindowScene *)scene API_AVAILABLE(ios(13.0));
+
 #pragma mark - Network Debugging
 
 /// If this property is set to YES, FLEX will swizzle NSURLConnection*Delegate and NSURLSession*Delegate methods

+ 26 - 0
Classes/Manager/FLEXManager.m

@@ -7,6 +7,7 @@
 //
 
 #import "FLEXManager.h"
+#import "FLEXUtility.h"
 #import "FLEXExplorerViewController.h"
 #import "FLEXWindow.h"
 #import "FLEXGlobalsEntry.h"
@@ -77,6 +78,21 @@
 - (void)showExplorer
 {
     self.explorerWindow.hidden = NO;
+#if FLEX_AT_LEAST_IOS13_SDK
+    if (@available(iOS 13.0, *)) {
+        // Only look for a new scene if the one we have isn't the active scene
+        if (self.explorerWindow.windowScene.activationState != UISceneActivationStateForegroundActive) {
+            for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
+                // Look for an active UIWindowScene
+                if (scene.activationState == UISceneActivationStateForegroundActive &&
+                    [scene isKindOfClass:[UIWindowScene class]]) {
+                    self.explorerWindow.windowScene = (UIWindowScene)scene;
+                    break;
+                }
+            }
+        }
+    }
+#endif
 }
 
 - (void)hideExplorer
@@ -92,6 +108,16 @@
     }
 }
 
+#if FLEX_AT_LEAST_IOS13_SDK
+- (void)showExplorerFromScene:(UIWindowScene *)scene
+{
+    if (@available(iOS 13.0, *)) {
+        self.explorerWindow.windowScene = scene;
+    }
+    self.explorerWindow.hidden = NO;
+}
+#endif
+
 - (BOOL)isHidden
 {
     return self.explorerWindow.isHidden;