-
Notifications
You must be signed in to change notification settings - Fork 1.7k
FIRMessagingRemoteNotificationsProxy updated to use GULAppDelegateSwizzler #2683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b2eabf2
4ab86de
1f1560a
f4a4638
9fcedce
27c8b5b
dee28d3
5821591
908b6ea
9e377d2
7861cde
b7703ac
ad1da54
2bdf353
8eafece
e5d2ce8
86ff257
79b7613
98ffccb
cd44395
3df4140
dcd0e10
18381dd
dae75d9
6dee8d3
2726e7c
63fd1f5
4a3fbb1
b390f4f
236877d
3641d35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…sts added. Cleanup
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,15 +31,13 @@ | |
@"userNotificationCenter:willPresentNotification:withCompletionHandler:"; | ||
static NSString *kUserNotificationDidReceiveResponseSelectorString = | ||
@"userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:"; | ||
static NSString *kReceiveDataMessageSelectorString = @"messaging:didReceiveMessage:"; | ||
|
||
@interface FIRMessagingRemoteNotificationsProxy () <UIApplicationDelegate> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an alternative than following this protocol? This makes macOS support very hard . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refer comment below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chliangGoogle Does FCM support MacOS now? If not, I can take care of MacOS support for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maksymmalyhin FCM does not yet support MacOS. It recently added tvOS See https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseMessaging.podspec#L22 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @paulb777 It looks like tvOS has no difference in the App Delegate, so supporting tvOS by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will we make GULAppDelegateSwizzler macOS support in this PR? If not, we can add a todo and fix in another PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a ticket for this #2706 |
||
|
||
@property(strong, nonatomic) NSMutableDictionary<NSString *, NSValue *> *originalAppDelegateImps; | ||
@property(strong, nonatomic) NSMutableDictionary<NSString *, NSArray *> *swizzledSelectorsByClass; | ||
|
||
@property(nonatomic) BOOL didSwizzleMethods; | ||
@property(nonatomic) BOOL didSwizzleAppDelegateMethods; | ||
|
||
@property(nonatomic) BOOL hasSwizzledUserNotificationDelegate; | ||
@property(nonatomic) BOOL isObservingUserNotificationDelegateChanges; | ||
|
@@ -92,13 +90,6 @@ - (void)swizzleMethodsIfPossible { | |
[GULAppDelegateSwizzler proxyOriginalDelegate]; | ||
self.appDelegateInterceptorID = [GULAppDelegateSwizzler registerAppDelegateInterceptor:self]; | ||
|
||
UIApplication *application = [GULAppDelegateSwizzler sharedApplication]; | ||
if (!application) { | ||
return; | ||
} | ||
NSObject<UIApplicationDelegate> *appDelegate = [application delegate]; | ||
[self swizzleAppDelegateMethods:appDelegate]; | ||
|
||
// Add KVO listener on [UNUserNotificationCenter currentNotificationCenter]'s delegate property | ||
Class notificationCenterClass = NSClassFromString(@"UNUserNotificationCenter"); | ||
if (notificationCenterClass) { | ||
|
@@ -127,24 +118,6 @@ - (void)unswizzleAllMethods { | |
[self.swizzledSelectorsByClass removeAllObjects]; | ||
} | ||
|
||
- (void)swizzleAppDelegateMethods:(id<UIApplicationDelegate>)appDelegate { | ||
Class appDelegateClass = [appDelegate class]; | ||
|
||
BOOL didSwizzleAppDelegate = NO; | ||
|
||
// For data message from MCS. | ||
SEL receiveDataMessageSelector = NSSelectorFromString(kReceiveDataMessageSelectorString); | ||
if ([appDelegate respondsToSelector:receiveDataMessageSelector]) { | ||
[self swizzleSelector:receiveDataMessageSelector | ||
inClass:appDelegateClass | ||
withImplementation:(IMP)FCM_swizzle_messagingDidReceiveMessage | ||
inProtocol:@protocol(UIApplicationDelegate)]; | ||
didSwizzleAppDelegate = YES; | ||
} | ||
|
||
self.didSwizzleAppDelegateMethods = didSwizzleAppDelegate; | ||
} | ||
|
||
- (void)listenForDelegateChangesInUserNotificationCenter:(id)notificationCenter { | ||
Class notificationCenterClass = NSClassFromString(@"UNUserNotificationCenter"); | ||
if (![notificationCenter isKindOfClass:notificationCenterClass]) { | ||
|
@@ -446,37 +419,6 @@ - (void)application:(UIApplication *)application | |
|
||
#pragma mark - Swizzled Methods | ||
|
||
void FCM_swizzle_appDidReceiveRemoteNotification(id self, | ||
SEL _cmd, | ||
UIApplication *app, | ||
NSDictionary *userInfo) { | ||
[[FIRMessaging messaging] appDidReceiveMessage:userInfo]; | ||
|
||
IMP original_imp = | ||
[[FIRMessagingRemoteNotificationsProxy sharedProxy] originalImplementationForSelector:_cmd]; | ||
if (original_imp) { | ||
((void (*)(id, SEL, UIApplication *, NSDictionary *))original_imp)(self, | ||
_cmd, | ||
app, | ||
userInfo); | ||
} | ||
} | ||
|
||
void FCM_swizzle_appDidReceiveRemoteNotificationWithHandler( | ||
id self, SEL _cmd, UIApplication *app, NSDictionary *userInfo, | ||
void (^handler)(UIBackgroundFetchResult)) { | ||
|
||
[[FIRMessaging messaging] appDidReceiveMessage:userInfo]; | ||
|
||
IMP original_imp = | ||
[[FIRMessagingRemoteNotificationsProxy sharedProxy] originalImplementationForSelector:_cmd]; | ||
if (original_imp) { | ||
((void (*)(id, SEL, UIApplication *, NSDictionary *, | ||
void (^)(UIBackgroundFetchResult)))original_imp)( | ||
self, _cmd, app, userInfo, handler); | ||
} | ||
} | ||
|
||
/** | ||
* Swizzle the notification handler for iOS 10+ devices. | ||
* Signature of original handler is as below: | ||
|
@@ -652,46 +594,4 @@ id userInfoFromNotification(id notification) { | |
return notificationUserInfo; | ||
} | ||
|
||
void FCM_swizzle_messagingDidReceiveMessage(id self, SEL _cmd, FIRMessaging *message, | ||
FIRMessagingRemoteMessage *remoteMessage) { | ||
[[FIRMessaging messaging] appDidReceiveMessage:remoteMessage.appData]; | ||
|
||
IMP original_imp = | ||
[[FIRMessagingRemoteNotificationsProxy sharedProxy] originalImplementationForSelector:_cmd]; | ||
if (original_imp) { | ||
((void (*)(id, SEL, FIRMessaging *, FIRMessagingRemoteMessage *))original_imp)( | ||
self, _cmd, message, remoteMessage); | ||
} | ||
} | ||
|
||
void FCM_swizzle_appDidFailToRegisterForRemoteNotifications(id self, | ||
SEL _cmd, | ||
UIApplication *app, | ||
NSError *error) { | ||
// Log the fact that we failed to register for remote notifications | ||
FIRMessagingLoggerError(kFIRMessagingMessageCodeRemoteNotificationsProxyAPNSFailed, | ||
@"Error in " | ||
@"application:didFailToRegisterForRemoteNotificationsWithError: %@", | ||
error.localizedDescription); | ||
IMP original_imp = | ||
[[FIRMessagingRemoteNotificationsProxy sharedProxy] originalImplementationForSelector:_cmd]; | ||
if (original_imp) { | ||
((void (*)(id, SEL, UIApplication *, NSError *))original_imp)(self, _cmd, app, error); | ||
} | ||
} | ||
|
||
void FCM_swizzle_appDidRegisterForRemoteNotifications(id self, | ||
SEL _cmd, | ||
UIApplication *app, | ||
NSData *deviceToken) { | ||
// Pass the APNSToken along to FIRMessaging (and auto-detect the token type) | ||
[FIRMessaging messaging].APNSToken = deviceToken; | ||
|
||
IMP original_imp = | ||
[[FIRMessagingRemoteNotificationsProxy sharedProxy] originalImplementationForSelector:_cmd]; | ||
if (original_imp) { | ||
((void (*)(id, SEL, UIApplication *, NSData *))original_imp)(self, _cmd, app, deviceToken); | ||
} | ||
} | ||
|
||
@end |
Uh oh!
There was an error while loading. Please reload this page.