aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Messaging
diff options
context:
space:
mode:
Diffstat (limited to 'Firebase/Messaging')
-rw-r--r--Firebase/Messaging/FIRMessaging+FIRApp.m12
-rw-r--r--Firebase/Messaging/FIRMessaging.m45
-rw-r--r--Firebase/Messaging/FIRMessagingClient.m7
-rw-r--r--Firebase/Messaging/FIRMessagingConnection.m4
-rw-r--r--Firebase/Messaging/FIRMessagingContextManagerService.m2
-rw-r--r--Firebase/Messaging/FIRMessagingDataMessageManager.m2
-rw-r--r--Firebase/Messaging/FIRMessagingDelayedMessageQueue.m2
-rw-r--r--Firebase/Messaging/FIRMessagingLogger.m4
-rw-r--r--Firebase/Messaging/FIRMessagingRmq2PersistentStore.m4
-rw-r--r--Firebase/Messaging/FIRMessagingRmqManager.m2
-rw-r--r--Firebase/Messaging/FIRMessagingUtilities.m2
-rw-r--r--Firebase/Messaging/FIRMessaging_Private.h3
-rw-r--r--Firebase/Messaging/Public/FIRMessaging.h15
13 files changed, 89 insertions, 15 deletions
diff --git a/Firebase/Messaging/FIRMessaging+FIRApp.m b/Firebase/Messaging/FIRMessaging+FIRApp.m
index 58ae3af..4ad7d4e 100644
--- a/Firebase/Messaging/FIRMessaging+FIRApp.m
+++ b/Firebase/Messaging/FIRMessaging+FIRApp.m
@@ -16,8 +16,16 @@
#import "FIRMessaging+FIRApp.h"
-#import <FirebaseCore/FIRAppInternal.h>
-#import <FirebaseCore/FIROptionsInternal.h>
+#ifdef COCOAPODS
+#import "FIRAppInternal.h"
+#else
+#import "third_party/firebase/ios/Source/FirebaseCore/Library/Private/FIRAppInternal.h"
+#endif
+#ifdef COCOAPODS
+#import "FIROptionsInternal.h"
+#else
+#import "third_party/firebase/ios/Source/FirebaseCore/Library/Private/FIROptionsInternal.h"
+#endif
#import "FIRMessagingConstants.h"
#import "FIRMessagingLogger.h"
diff --git a/Firebase/Messaging/FIRMessaging.m b/Firebase/Messaging/FIRMessaging.m
index 64b1ef8..2a14e04 100644
--- a/Firebase/Messaging/FIRMessaging.m
+++ b/Firebase/Messaging/FIRMessaging.m
@@ -37,7 +37,11 @@
#import "FIRMessagingUtilities.h"
#import "FIRMessagingVersionUtilities.h"
+#ifdef COCOAPODS
#import "FIRReachabilityChecker.h"
+#else
+#import "third_party/firebase/ios/Source/FirebaseCore/Library/Private/FIRReachabilityChecker.h"
+#endif
#import "NSError+FIRMessaging.h"
@@ -70,6 +74,14 @@ NSString * const FIRMessagingRegistrationTokenRefreshedNotification =
@"com.firebase.messaging.notif.fcm-token-refreshed";
#endif // defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
+NSString *const kFIRMessagingUserDefaultsKeyAutoInitEnabled =
+ @"com.firebase.messaging.auto-init.enabled"; // Auto Init Enabled key stored in NSUserDefaults
+NSString *const kFIRMessagingSuiteName =
+ @"com.firebase.messaging.user_defaults"; // Suite name for NSUserDefaults
+
+static NSString *const kFIRMessagingPlistAutoInitEnabled =
+ @"FirebaseMessagingAutoInitEnabled"; // Auto Init Enabled key stored in Info.plist
+
// Copied from Apple's header in case it is missing in some cases (e.g. pre-Xcode 8 builds).
#ifndef NSFoundationVersionNumber_iOS_8_x_Max
#define NSFoundationVersionNumber_iOS_8_x_Max 1199
@@ -120,8 +132,8 @@ NSString * const FIRMessagingRegistrationTokenRefreshedNotification =
@end
-@interface FIRMessaging ()
- <FIRMessagingClientDelegate, FIRMessagingReceiverDelegate, FIRReachabilityDelegate>
+@interface FIRMessaging ()<FIRMessagingClientDelegate, FIRMessagingReceiverDelegate,
+ FIRReachabilityDelegate>
// FIRApp properties
@property(nonatomic, readwrite, copy) NSString *fcmSenderID;
@@ -141,6 +153,7 @@ NSString * const FIRMessagingRegistrationTokenRefreshedNotification =
@property(nonatomic, readwrite, strong) FIRMessagingRmqManager *rmq2Manager;
@property(nonatomic, readwrite, strong) FIRMessagingReceiver *receiver;
@property(nonatomic, readwrite, strong) FIRMessagingSyncMessageManager *syncMessageManager;
+@property(nonatomic, readwrite, strong) NSUserDefaults *messagingUserDefaults;
/// Message ID's logged for analytics. This prevents us from logging the same message twice
/// which can happen if the user inadvertently calls `appDidReceiveMessage` along with us
@@ -166,6 +179,7 @@ NSString * const FIRMessagingRegistrationTokenRefreshedNotification =
if (self) {
_loggedMessageIDs = [NSMutableSet set];
_instanceIDProxy = [[FIRMessagingInstanceIDProxy alloc] init];
+ _messagingUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingSuiteName];
}
return self;
}
@@ -448,6 +462,33 @@ NSString * const FIRMessagingRegistrationTokenRefreshedNotification =
#pragma mark - FCM
+- (BOOL)isAutoInitEnabled {
+ // Check storage
+ id isAutoInitEnabledObject =
+ [_messagingUserDefaults objectForKey:kFIRMessagingUserDefaultsKeyAutoInitEnabled];
+ if (isAutoInitEnabledObject) {
+ return [isAutoInitEnabledObject boolValue];
+ }
+
+ // Check Info.plist
+ isAutoInitEnabledObject =
+ [[NSBundle mainBundle] objectForInfoDictionaryKey:kFIRMessagingPlistAutoInitEnabled];
+ if (isAutoInitEnabledObject) {
+ return [isAutoInitEnabledObject boolValue];
+ }
+ // If none of above exists, we default assume FCM auto init is enabled.
+ return YES;
+}
+
+- (void)setAutoInitEnabled:(BOOL)autoInitEnabled {
+ BOOL isFCMAutoInitEnabled = [self isAutoInitEnabled];
+ [_messagingUserDefaults setBool:autoInitEnabled
+ forKey:kFIRMessagingUserDefaultsKeyAutoInitEnabled];
+ if (!isFCMAutoInitEnabled && autoInitEnabled) {
+ self.defaultFcmToken = [self FCMToken];
+ }
+}
+
- (NSString *)FCMToken {
NSString *token = self.defaultFcmToken;
if (!token) {
diff --git a/Firebase/Messaging/FIRMessagingClient.m b/Firebase/Messaging/FIRMessagingClient.m
index 13e1775..e0fc8c4 100644
--- a/Firebase/Messaging/FIRMessagingClient.m
+++ b/Firebase/Messaging/FIRMessagingClient.m
@@ -16,6 +16,12 @@
#import "FIRMessagingClient.h"
+#ifdef COCOAPODS
+#import "FIRReachabilityChecker.h"
+#else
+#import "third_party/firebase/ios/Source/FirebaseCore/Library/Private/FIRReachabilityChecker.h"
+#endif
+
#import "FIRMessagingConnection.h"
#import "FIRMessagingConstants.h"
#import "FIRMessagingDataMessageManager.h"
@@ -25,7 +31,6 @@
#import "FIRMessagingRmqManager.h"
#import "FIRMessagingTopicsCommon.h"
#import "FIRMessagingUtilities.h"
-#import "FIRReachabilityChecker.h"
#import "NSError+FIRMessaging.h"
static const NSTimeInterval kConnectTimeoutInterval = 40.0;
diff --git a/Firebase/Messaging/FIRMessagingConnection.m b/Firebase/Messaging/FIRMessagingConnection.m
index afbd0ba..4d25ba1 100644
--- a/Firebase/Messaging/FIRMessagingConnection.m
+++ b/Firebase/Messaging/FIRMessagingConnection.m
@@ -16,8 +16,8 @@
#import "FIRMessagingConnection.h"
-#import "Protos/GtalkCore.pbobjc.h"
-#import "Protos/GtalkExtensions.pbobjc.h"
+#import "third_party/firebase/ios/Source/FirebaseMessaging/Library/Protos/GtalkCore.pbobjc.h"
+#import "third_party/firebase/ios/Source/FirebaseMessaging/Library/Protos/GtalkExtensions.pbobjc.h"
#import "FIRMessaging.h"
#import "FIRMessagingDataMessageManager.h"
diff --git a/Firebase/Messaging/FIRMessagingContextManagerService.m b/Firebase/Messaging/FIRMessagingContextManagerService.m
index 1c9f653..232587f 100644
--- a/Firebase/Messaging/FIRMessagingContextManagerService.m
+++ b/Firebase/Messaging/FIRMessagingContextManagerService.m
@@ -143,7 +143,7 @@ typedef NS_ENUM(NSUInteger, FIRMessagingContextManagerMessageType) {
}
if ([apsDictionary[kFIRMessagingContextManagerTitleKey] length]) {
// |alertTitle| is iOS 8.2+, so check if we can set it
- if ([notification respondsToSelector:@selector(setAlertTitle:)]) {
+ if ([notification respondsToSelector:@selector(setAlertTitle:)]) {
notification.alertTitle = apsDictionary[kFIRMessagingContextManagerTitleKey];
}
}
diff --git a/Firebase/Messaging/FIRMessagingDataMessageManager.m b/Firebase/Messaging/FIRMessagingDataMessageManager.m
index 58dae87..0822c2c 100644
--- a/Firebase/Messaging/FIRMessagingDataMessageManager.m
+++ b/Firebase/Messaging/FIRMessagingDataMessageManager.m
@@ -16,7 +16,7 @@
#import "FIRMessagingDataMessageManager.h"
-#import "Protos/GtalkCore.pbobjc.h"
+#import "third_party/firebase/ios/Source/FirebaseMessaging/Library/Protos/GtalkCore.pbobjc.h"
#import "FIRMessagingClient.h"
#import "FIRMessagingConnection.h"
diff --git a/Firebase/Messaging/FIRMessagingDelayedMessageQueue.m b/Firebase/Messaging/FIRMessagingDelayedMessageQueue.m
index 0371c02..55e9b8c 100644
--- a/Firebase/Messaging/FIRMessagingDelayedMessageQueue.m
+++ b/Firebase/Messaging/FIRMessagingDelayedMessageQueue.m
@@ -16,7 +16,7 @@
#import "FIRMessagingDelayedMessageQueue.h"
-#import "Protos/GtalkCore.pbobjc.h"
+#import "third_party/firebase/ios/Source/FirebaseMessaging/Library/Protos/GtalkCore.pbobjc.h"
#import "FIRMessagingDefines.h"
#import "FIRMessagingRmqManager.h"
diff --git a/Firebase/Messaging/FIRMessagingLogger.m b/Firebase/Messaging/FIRMessagingLogger.m
index ee4e771..abe8233 100644
--- a/Firebase/Messaging/FIRMessagingLogger.m
+++ b/Firebase/Messaging/FIRMessagingLogger.m
@@ -16,7 +16,11 @@
#import "FIRMessagingLogger.h"
+#ifdef COCOAPODS
#import "FIRLogger.h"
+#else
+#import "third_party/firebase/ios/Source/FirebaseCore/Library/Private/FIRLogger.h"
+#endif
@implementation FIRMessagingLogger
diff --git a/Firebase/Messaging/FIRMessagingRmq2PersistentStore.m b/Firebase/Messaging/FIRMessagingRmq2PersistentStore.m
index a85298c..7b61517 100644
--- a/Firebase/Messaging/FIRMessagingRmq2PersistentStore.m
+++ b/Firebase/Messaging/FIRMessagingRmq2PersistentStore.m
@@ -18,7 +18,7 @@
#import "sqlite3.h"
-#import "Protos/GtalkCore.pbobjc.h"
+#import "third_party/firebase/ios/Source/FirebaseMessaging/Library/Protos/GtalkCore.pbobjc.h"
#import "FIRMessagingConstants.h"
#import "FIRMessagingDefines.h"
@@ -105,7 +105,7 @@ typedef void(^FCMOutgoingRmqMessagesTableHandler)(int64_t rmqId, int8_t tag, NSD
// Utility to create an NSString from a sqlite3 result code
NSString * _Nonnull FIRMessagingStringFromSQLiteResult(int result) {
const char *errorStr = sqlite3_errstr(result);
- NSString *errorString = [NSString stringWithFormat:@"%d - %s", result, errorStr];
+ NSString *errorString = [NSString stringWithFormat:@"%d - %s", result, errorStr];
return errorString;
}
diff --git a/Firebase/Messaging/FIRMessagingRmqManager.m b/Firebase/Messaging/FIRMessagingRmqManager.m
index de63a73..6062ba0 100644
--- a/Firebase/Messaging/FIRMessagingRmqManager.m
+++ b/Firebase/Messaging/FIRMessagingRmqManager.m
@@ -16,7 +16,7 @@
#import "FIRMessagingRmqManager.h"
-#import "Protos/GtalkCore.pbobjc.h"
+#import "third_party/firebase/ios/Source/FirebaseMessaging/Library/Protos/GtalkCore.pbobjc.h"
#import "sqlite3.h"
#import "FIRMessagingDefines.h"
diff --git a/Firebase/Messaging/FIRMessagingUtilities.m b/Firebase/Messaging/FIRMessagingUtilities.m
index 60f3f28..f377561 100644
--- a/Firebase/Messaging/FIRMessagingUtilities.m
+++ b/Firebase/Messaging/FIRMessagingUtilities.m
@@ -16,7 +16,7 @@
#import "FIRMessagingUtilities.h"
-#import "Protos/GtalkCore.pbobjc.h"
+#import "third_party/firebase/ios/Source/FirebaseMessaging/Library/Protos/GtalkCore.pbobjc.h"
#import "FIRMessagingLogger.h"
diff --git a/Firebase/Messaging/FIRMessaging_Private.h b/Firebase/Messaging/FIRMessaging_Private.h
index 0c35179..135f091 100644
--- a/Firebase/Messaging/FIRMessaging_Private.h
+++ b/Firebase/Messaging/FIRMessaging_Private.h
@@ -25,6 +25,9 @@ typedef NS_ENUM(int8_t, FIRMessagingNetworkStatus) {
kFIRMessagingReachabilityReachableViaWWAN,
};
+FOUNDATION_EXPORT NSString *const kFIRMessagingUserDefaultsKeyAutoInitEnabled;
+FOUNDATION_EXPORT NSString *const kFIRMessagingSuiteName;
+
@interface FIRMessagingRemoteMessage ()
@property(nonatomic, strong) NSDictionary *appData;
diff --git a/Firebase/Messaging/Public/FIRMessaging.h b/Firebase/Messaging/Public/FIRMessaging.h
index 7cd7b19..33dd596 100644
--- a/Firebase/Messaging/Public/FIRMessaging.h
+++ b/Firebase/Messaging/Public/FIRMessaging.h
@@ -289,7 +289,6 @@ NS_SWIFT_NAME(Messaging)
*/
@property(nonatomic, weak, nullable) id<FIRMessagingDelegate> delegate;
-
/**
* Delegate to handle remote data messages received via FCM for devices running iOS 10 or above.
*/
@@ -354,6 +353,20 @@ NS_SWIFT_NAME(Messaging)
#pragma mark - FCM Tokens
/**
+ * Is Firebase Messaging token auto generation enabled? If this flag is disabled,
+ * Firebase Messaging will not generate token automatically for message delivery.
+ *
+ * This setting is persisted, and is applied on future
+ * invocations of your application. Once explicitly set, it overrides any
+ * settings in your Info.plist.
+ *
+ * By default, FCM automatic initialization is enabled. If you need to change the
+ * default (for example, because you want to prompt the user before getting token)
+ * set FirebaseMessagingAutoInitEnabled to false in your application's Info.plist.
+ */
+@property(nonatomic, assign, getter=isAutoInitEnabled) BOOL autoInitEnabled;
+
+/**
* The FCM token is used to identify this device so that FCM can send notifications to it.
* It is associated with your APNS token when the APNS token is supplied, so that sending
* messages to the FCM token will be delivered over APNS.