|
31 | 31 | #import "FIRMessagingLogger.h" |
32 | 32 | #import "FIRMessagingPubSub.h" |
33 | 33 | #import "FIRMessagingReceiver.h" |
| 34 | +#import "FIRMessagingRemoteNotificationsProxy.h" |
34 | 35 | #import "FIRMessagingRmqManager.h" |
35 | 36 | #import "FIRMessagingSyncMessageManager.h" |
36 | 37 | #import "FIRMessagingUtilities.h" |
37 | 38 | #import "FIRMessagingVersionUtilities.h" |
| 39 | +#import "FIRMessaging_Private.h" |
38 | 40 |
|
39 | 41 | #import <FirebaseCore/FIRAppInternal.h> |
40 | 42 | #import <FirebaseInstanceID/FirebaseInstanceID.h> |
@@ -190,6 +192,45 @@ - (void)dealloc { |
190 | 192 |
|
191 | 193 | #pragma mark - Config |
192 | 194 |
|
| 195 | ++ (void)load { |
| 196 | + [[NSNotificationCenter defaultCenter] addObserver:self |
| 197 | + selector:@selector(didReceiveConfigureSDKNotification:) |
| 198 | + name:kFIRAppReadyToConfigureSDKNotification |
| 199 | + object:nil]; |
| 200 | +} |
| 201 | + |
| 202 | ++ (void)didReceiveConfigureSDKNotification:(NSNotification *)notification { |
| 203 | + NSDictionary *appInfoDict = notification.userInfo; |
| 204 | + NSNumber *isDefaultApp = appInfoDict[kFIRAppIsDefaultAppKey]; |
| 205 | + if (![isDefaultApp boolValue]) { |
| 206 | + // Only configure for the default FIRApp. |
| 207 | + FIRMessagingLoggerDebug(kFIRMessagingMessageCodeFIRApp001, |
| 208 | + @"Firebase Messaging only works with the default app."); |
| 209 | + return; |
| 210 | + } |
| 211 | + |
| 212 | + NSString *appName = appInfoDict[kFIRAppNameKey]; |
| 213 | + FIRApp *app = [FIRApp appNamed:appName]; |
| 214 | + [[FIRMessaging messaging] configureMessaging:app]; |
| 215 | +} |
| 216 | + |
| 217 | +- (void)configureMessaging:(FIRApp *)app { |
| 218 | + // Swizzle remote-notification-related methods (app delegate and UNUserNotificationCenter) |
| 219 | + if ([FIRMessagingRemoteNotificationsProxy canSwizzleMethods]) { |
| 220 | + NSString *docsURLString = @"https://firebase.google.com/docs/cloud-messaging/ios/client" |
| 221 | + @"#method_swizzling_in_firebase_messaging"; |
| 222 | + FIRMessagingLoggerNotice(kFIRMessagingMessageCodeFIRApp000, |
| 223 | + @"FIRMessaging Remote Notifications proxy enabled, will swizzle " |
| 224 | + @"remote notification receiver handlers. If you'd prefer to manually " |
| 225 | + @"integrate Firebase Messaging, add \"%@\" to your Info.plist, " |
| 226 | + @"and set it to NO. Follow the instructions at:\n%@\nto ensure " |
| 227 | + @"proper integration.", |
| 228 | + kFIRMessagingRemoteNotificationsProxyEnabledInfoPlistKey, |
| 229 | + docsURLString); |
| 230 | + [FIRMessagingRemoteNotificationsProxy swizzleMethods]; |
| 231 | + } |
| 232 | +} |
| 233 | + |
193 | 234 | - (void)start { |
194 | 235 | // Print the library version for logging. |
195 | 236 | NSString *currentLibraryVersion = FIRMessagingCurrentLibraryVersion(); |
|
0 commit comments