diff --git a/Example/Firebase.xcodeproj/project.pbxproj b/Example/Firebase.xcodeproj/project.pbxproj index 2003bd16f32..ed8e1db142e 100644 --- a/Example/Firebase.xcodeproj/project.pbxproj +++ b/Example/Firebase.xcodeproj/project.pbxproj @@ -6631,12 +6631,12 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = ""; HEADER_SEARCH_PATHS = ( "$(inherited)", "${PODS_ROOT}/Headers/Private", ); - DEBUG_INFORMATION_FORMAT = dwarf; - DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "Core/Tests/Tests-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 10.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -6653,13 +6653,13 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NONNULL = YES; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = ""; HEADER_SEARCH_PATHS = ( "$(inherited)", "${PODS_ROOT}/Headers/Private", ); - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "Core/Tests/Tests-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 10.2; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; diff --git a/Firebase/Messaging/FIRMessaging+FIRApp.h b/Firebase/Messaging/FIRMessaging+FIRApp.h deleted file mode 100644 index 743b0f4c310..00000000000 --- a/Firebase/Messaging/FIRMessaging+FIRApp.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "FIRMessaging.h" - -/** - * This category extends FIRMessaging with the configuration for using Cloud Messaging. - */ -@interface FIRMessaging (FIRApp) - -@end diff --git a/Firebase/Messaging/FIRMessaging+FIRApp.m b/Firebase/Messaging/FIRMessaging+FIRApp.m deleted file mode 100644 index dda360c3cff..00000000000 --- a/Firebase/Messaging/FIRMessaging+FIRApp.m +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "FIRMessaging+FIRApp.h" - -#import -#import - -#import "FIRMessagingConstants.h" -#import "FIRMessagingLogger.h" -#import "FIRMessagingPubSub.h" -#import "FIRMessagingRemoteNotificationsProxy.h" -#import "FIRMessagingVersionUtilities.h" -#import "FIRMessaging_Private.h" - -@implementation FIRMessaging (FIRApp) - -+ (void)load { - // FIRMessaging by default removes itself from observing any notifications. - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(didReceiveConfigureSDKNotification:) - name:kFIRAppReadyToConfigureSDKNotification - object:[FIRApp class]]; -} - -+ (void)didReceiveConfigureSDKNotification:(NSNotification *)notification { - NSDictionary *appInfoDict = notification.userInfo; - NSNumber *isDefaultApp = appInfoDict[kFIRAppIsDefaultAppKey]; - if (![isDefaultApp boolValue]) { - // Only configure for the default FIRApp. - FIRMessagingLoggerDebug(kFIRMessagingMessageCodeFIRApp001, - @"Firebase Messaging only works with the default app."); - return; - } - - NSString *appName = appInfoDict[kFIRAppNameKey]; - FIRApp *app = [FIRApp appNamed:appName]; - [[FIRMessaging messaging] configureMessaging:app]; -} - -- (void)configureMessaging:(FIRApp *)app { - // Swizzle remote-notification-related methods (app delegate and UNUserNotificationCenter) - if ([FIRMessagingRemoteNotificationsProxy canSwizzleMethods]) { - NSString *docsURLString = @"https://firebase.google.com/docs/cloud-messaging/ios/client" - @"#method_swizzling_in_firebase_messaging"; - FIRMessagingLoggerNotice(kFIRMessagingMessageCodeFIRApp000, - @"FIRMessaging Remote Notifications proxy enabled, will swizzle " - @"remote notification receiver handlers. If you'd prefer to manually " - @"integrate Firebase Messaging, add \"%@\" to your Info.plist, " - @"and set it to NO. Follow the instructions at:\n%@\nto ensure " - @"proper integration.", - kFIRMessagingRemoteNotificationsProxyEnabledInfoPlistKey, - docsURLString); - [FIRMessagingRemoteNotificationsProxy swizzleMethods]; - } -} - -- (void)exitApp:(FIRApp *)app withError:(NSError *)error { - [app sendLogsWithServiceName:kFIRServiceMessaging - version:FIRMessagingCurrentLibraryVersion() - error:error]; - if (error) { - NSString *message = nil; - if (app.options.usingOptionsFromDefaultPlist) { - // Configured using plist file - message = [NSString stringWithFormat:@"Firebase Messaging has stopped your project because " - @"there are missing or incorrect values provided in %@.%@ that may prevent " - @"your app from behaving as expected:\n\n" - @"Error: %@\n\n" - @"Please fix these issues to ensure that Firebase is correctly configured in " - @"your project.", - kServiceInfoFileName, - kServiceInfoFileType, - error.localizedFailureReason]; - } else { - // Configured manually - message = [NSString stringWithFormat:@"Firebase Messaging has stopped your project because " - @"there are missing or incorrect values in Firebase's configuration options " - @"that may prevent your app from behaving as expected:\n\n" - @"Error:%@\n\n" - @"Please fix these issues to ensure that Firebase is correctly configured in " - @"your project.", - error.localizedFailureReason]; - } - [NSException raise:kFirebaseCloudMessagingErrorDomain format:@"%@", message]; - } -} - -@end diff --git a/Firebase/Messaging/FIRMessaging.m b/Firebase/Messaging/FIRMessaging.m index 105f655d311..932a623aa2f 100644 --- a/Firebase/Messaging/FIRMessaging.m +++ b/Firebase/Messaging/FIRMessaging.m @@ -31,10 +31,12 @@ #import "FIRMessagingLogger.h" #import "FIRMessagingPubSub.h" #import "FIRMessagingReceiver.h" +#import "FIRMessagingRemoteNotificationsProxy.h" #import "FIRMessagingRmqManager.h" #import "FIRMessagingSyncMessageManager.h" #import "FIRMessagingUtilities.h" #import "FIRMessagingVersionUtilities.h" +#import "FIRMessaging_Private.h" #import #import @@ -190,6 +192,45 @@ - (void)dealloc { #pragma mark - Config ++ (void)load { + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(didReceiveConfigureSDKNotification:) + name:kFIRAppReadyToConfigureSDKNotification + object:nil]; +} + ++ (void)didReceiveConfigureSDKNotification:(NSNotification *)notification { + NSDictionary *appInfoDict = notification.userInfo; + NSNumber *isDefaultApp = appInfoDict[kFIRAppIsDefaultAppKey]; + if (![isDefaultApp boolValue]) { + // Only configure for the default FIRApp. + FIRMessagingLoggerDebug(kFIRMessagingMessageCodeFIRApp001, + @"Firebase Messaging only works with the default app."); + return; + } + + NSString *appName = appInfoDict[kFIRAppNameKey]; + FIRApp *app = [FIRApp appNamed:appName]; + [[FIRMessaging messaging] configureMessaging:app]; +} + +- (void)configureMessaging:(FIRApp *)app { + // Swizzle remote-notification-related methods (app delegate and UNUserNotificationCenter) + if ([FIRMessagingRemoteNotificationsProxy canSwizzleMethods]) { + NSString *docsURLString = @"https://firebase.google.com/docs/cloud-messaging/ios/client" + @"#method_swizzling_in_firebase_messaging"; + FIRMessagingLoggerNotice(kFIRMessagingMessageCodeFIRApp000, + @"FIRMessaging Remote Notifications proxy enabled, will swizzle " + @"remote notification receiver handlers. If you'd prefer to manually " + @"integrate Firebase Messaging, add \"%@\" to your Info.plist, " + @"and set it to NO. Follow the instructions at:\n%@\nto ensure " + @"proper integration.", + kFIRMessagingRemoteNotificationsProxyEnabledInfoPlistKey, + docsURLString); + [FIRMessagingRemoteNotificationsProxy swizzleMethods]; + } +} + - (void)start { // Print the library version for logging. NSString *currentLibraryVersion = FIRMessagingCurrentLibraryVersion();