@@ -31,11 +31,6 @@ typedef BOOL (*GULRealOpenURLSourceApplicationAnnotationIMP)(
31
31
typedef BOOL (*GULRealOpenURLOptionsIMP)(
32
32
id , SEL , GULApplication *, NSURL *, NSDictionary <NSString *, id > *);
33
33
34
- #if UISCENE_SUPPORTED
35
- API_AVAILABLE (ios(13.0 ), tvos(13.0 ))
36
- typedef void (*GULOpenURLContextsIMP)(id , SEL , UIScene *, NSSet <UIOpenURLContext *> *);
37
- #endif // UISCENE_SUPPORTED
38
-
39
34
#pragma clang diagnostic push
40
35
#pragma clang diagnostic ignored "-Wstrict-prototypes"
41
36
typedef void (*GULRealHandleEventsForBackgroundURLSessionIMP)(
@@ -80,11 +75,12 @@ typedef void (*GULRealDidReceiveRemoteNotificationWithCompletionIMP)(
80
75
// Since Firebase SDKs also use this for app delegate proxying, in order to not be a breaking change
81
76
// we disable App Delegate proxying when either of these two flags are set to NO.
82
77
83
- /* * Plist key that allows Firebase developers to disable App Delegate Proxying. */
78
+ /* * Plist key that allows Firebase developers to disable App and Scene Delegate Proxying. */
84
79
static NSString *const kGULFirebaseAppDelegateProxyEnabledPlistKey =
85
80
@" FirebaseAppDelegateProxyEnabled" ;
86
81
87
- /* * Plist key that allows developers not using Firebase to disable App Delegate Proxying. */
82
+ /* * Plist key that allows developers not using Firebase to disable App and Scene Delegate Proxying.
83
+ */
88
84
static NSString *const kGULGoogleUtilitiesAppDelegateProxyEnabledPlistKey =
89
85
@" GoogleUtilitiesAppDelegateProxyEnabled" ;
90
86
@@ -294,20 +290,6 @@ + (void)proxyOriginalDelegate {
294
290
id <GULApplicationDelegate> originalDelegate =
295
291
[GULAppDelegateSwizzler sharedApplication ].delegate ;
296
292
[GULAppDelegateSwizzler proxyAppDelegate: originalDelegate];
297
-
298
- #if UISCENE_SUPPORTED
299
- if (@available (iOS 13.0 , tvOS 13.0 , *)) {
300
- if (![GULAppDelegateSwizzler isAppDelegateProxyEnabled ]) {
301
- return ;
302
- } else {
303
- [[NSNotificationCenter defaultCenter ]
304
- addObserver: self
305
- selector: @selector (handleSceneWillConnectToNotification: )
306
- name: UISceneWillConnectNotification
307
- object: nil ];
308
- }
309
- }
310
- #endif // UISCENE_SUPPORTED
311
293
});
312
294
}
313
295
@@ -703,17 +685,6 @@ + (void)notifyInterceptorsWithMethodSelector:(SEL)methodSelector
703
685
}];
704
686
}
705
687
706
- #if UISCENE_SUPPORTED
707
- + (void )handleSceneWillConnectToNotification : (NSNotification *)notification {
708
- if (@available (iOS 13.0 , tvOS 13.0 , *)) {
709
- if ([notification.object isKindOfClass: [UIScene class ]]) {
710
- UIScene *scene = (UIScene *)notification.object ;
711
- [GULAppDelegateSwizzler proxySceneDelegateIfNeeded: scene];
712
- }
713
- }
714
- }
715
- #endif // UISCENE_SUPPORTED
716
-
717
688
// The methods below are donor methods which are added to the dynamic subclass of the App Delegate.
718
689
// They are called within the scope of the real App Delegate so |self| does not refer to the
719
690
// GULAppDelegateSwizzler instance but the real App Delegate instance.
@@ -793,36 +764,6 @@ - (BOOL)application:(GULApplication *)application
793
764
794
765
#endif // TARGET_OS_IOS
795
766
796
- #pragma mark - [Donor Methods] UISceneDelegate URL handler
797
-
798
- #if UISCENE_SUPPORTED
799
- - (void )scene : (UIScene *)scene
800
- openURLContexts : (NSSet <UIOpenURLContext *> *)URLContexts API_AVAILABLE(ios(13.0 ), tvos(13.0 )) {
801
- if (@available (iOS 13.0 , tvOS 13.0 , *)) {
802
- SEL methodSelector = @selector (scene:openURLContexts: );
803
- // Call the real implementation if the real App Delegate has any.
804
- NSValue *openURLContextsIMPPointer =
805
- [GULAppDelegateSwizzler originalImplementationForSelector: methodSelector object: self ];
806
- GULOpenURLContextsIMP openURLContextsIMP = [openURLContextsIMPPointer pointerValue ];
807
-
808
- [GULAppDelegateSwizzler
809
- notifyInterceptorsWithMethodSelector: methodSelector
810
- callback: ^(id <GULApplicationDelegate> interceptor) {
811
- if ([interceptor
812
- conformsToProtocol: @protocol (UISceneDelegate)]) {
813
- id <UISceneDelegate> sceneInterceptor =
814
- (id <UISceneDelegate>)interceptor;
815
- [sceneInterceptor scene: scene openURLContexts: URLContexts];
816
- }
817
- }];
818
-
819
- if (openURLContextsIMP) {
820
- openURLContextsIMP (self, methodSelector, scene, URLContexts);
821
- }
822
- }
823
- }
824
- #endif // UISCENE_SUPPORTED
825
-
826
767
#pragma mark - [Donor Methods] Network overridden handler methods
827
768
828
769
#if TARGET_OS_IOS || TARGET_OS_TV
@@ -1065,97 +1006,6 @@ + (void)proxyAppDelegate:(id<GULApplicationDelegate>)appDelegate {
1065
1006
}
1066
1007
}
1067
1008
1068
- #if UISCENE_SUPPORTED
1069
- + (void )proxySceneDelegateIfNeeded : (UIScene *)scene {
1070
- Class realClass = [scene.delegate class ];
1071
- NSString *className = NSStringFromClass (realClass);
1072
-
1073
- // Skip proxying if failed to get the delegate class name for some reason (e.g. `delegate == nil`)
1074
- // or the class has a prefix of kGULAppDelegatePrefix, which means it has been proxied before.
1075
- if (className == nil || [className hasPrefix: kGULAppDelegatePrefix ]) {
1076
- return ;
1077
- }
1078
-
1079
- NSString *classNameWithPrefix = [kGULAppDelegatePrefix stringByAppendingString: className];
1080
- NSString *newClassName =
1081
- [NSString stringWithFormat: @" %@ -%@ " , classNameWithPrefix, [NSUUID UUID ].UUIDString];
1082
-
1083
- if (NSClassFromString (newClassName)) {
1084
- GULLogError (
1085
- kGULLoggerSwizzler , NO ,
1086
- [NSString
1087
- stringWithFormat: @" I-SWZ%06ld " ,
1088
- (long )kGULSwizzlerMessageCodeAppDelegateSwizzlingInvalidSceneDelegate ],
1089
- @" Cannot create a proxy for Scene Delegate. Subclass already exists. Original Class"
1090
- @" : %@ , subclass: %@ " ,
1091
- className, newClassName);
1092
- return ;
1093
- }
1094
-
1095
- // Register the new class as subclass of the real one. Do not allocate more than the real class
1096
- // size.
1097
- Class sceneDelegateSubClass = objc_allocateClassPair (realClass, newClassName.UTF8String , 0 );
1098
- if (sceneDelegateSubClass == Nil ) {
1099
- GULLogError (
1100
- kGULLoggerSwizzler , NO ,
1101
- [NSString
1102
- stringWithFormat: @" I-SWZ%06ld " ,
1103
- (long )kGULSwizzlerMessageCodeAppDelegateSwizzlingInvalidSceneDelegate ],
1104
- @" Cannot create a proxy for Scene Delegate. Subclass already exists. Original Class"
1105
- @" : %@ , subclass: Nil" ,
1106
- className);
1107
- return ;
1108
- }
1109
-
1110
- NSMutableDictionary <NSString *, NSValue *> *realImplementationsBySelector =
1111
- [[NSMutableDictionary alloc ] init ];
1112
-
1113
- // For scene:openURLContexts:
1114
- SEL openURLContextsSEL = @selector (scene:openURLContexts: );
1115
- [self proxyDestinationSelector: openURLContextsSEL
1116
- implementationsFromSourceSelector: openURLContextsSEL
1117
- fromClass: [GULAppDelegateSwizzler class ]
1118
- toClass: sceneDelegateSubClass
1119
- realClass: realClass
1120
- storeDestinationImplementationTo: realImplementationsBySelector];
1121
-
1122
- // Store original implementations to a fake property of the original delegate.
1123
- objc_setAssociatedObject (scene.delegate , &kGULRealIMPBySelectorKey ,
1124
- [realImplementationsBySelector copy ], OBJC_ASSOCIATION_RETAIN_NONATOMIC );
1125
- objc_setAssociatedObject (scene.delegate , &kGULRealClassKey , realClass,
1126
- OBJC_ASSOCIATION_RETAIN_NONATOMIC );
1127
-
1128
- // The subclass size has to be exactly the same size with the original class size. The subclass
1129
- // cannot have more ivars/properties than its superclass since it will cause an offset in memory
1130
- // that can lead to overwriting the isa of an object in the next frame.
1131
- if (class_getInstanceSize (realClass) != class_getInstanceSize (sceneDelegateSubClass)) {
1132
- GULLogError (
1133
- kGULLoggerSwizzler , NO ,
1134
- [NSString
1135
- stringWithFormat: @" I-SWZ%06ld " ,
1136
- (long )kGULSwizzlerMessageCodeAppDelegateSwizzlingInvalidSceneDelegate ],
1137
- @" Cannot create subclass of Scene Delegate, because the created subclass is not the "
1138
- @" same size. %@ " ,
1139
- className);
1140
- NSAssert (NO , @" Classes must be the same size to swizzle isa" );
1141
- return ;
1142
- }
1143
-
1144
- // Make the newly created class to be the subclass of the real Scene Delegate class.
1145
- objc_registerClassPair (sceneDelegateSubClass);
1146
- if (object_setClass (scene.delegate , sceneDelegateSubClass)) {
1147
- GULLogDebug (
1148
- kGULLoggerSwizzler , NO ,
1149
- [NSString
1150
- stringWithFormat: @" I-SWZ%06ld " ,
1151
- (long )kGULSwizzlerMessageCodeAppDelegateSwizzlingInvalidSceneDelegate ],
1152
- @" Successfully created Scene Delegate Proxy automatically. To disable the "
1153
- @" proxy, set the flag %@ to NO (Boolean) in the Info.plist" ,
1154
- [GULAppDelegateSwizzler correctAppDelegateProxyKey ]);
1155
- }
1156
- }
1157
- #endif // UISCENE_SUPPORTED
1158
-
1159
1009
#pragma mark - Methods to print correct debug logs
1160
1010
1161
1011
+ (NSString *)correctAppDelegateProxyKey {
0 commit comments