From 08f447cd3fffae80748239daada493fcc19c111f Mon Sep 17 00:00:00 2001 From: Ryan Wilson Date: Mon, 14 May 2018 10:02:25 -0700 Subject: Add global data collection switch. (#1219) * Addition of global data collection switch. * Added Messaging conformance to data switch. Also formatted code. * Move data collection flag internal until all SDKs conform to it. * Formatting in response to code review. --- Firebase/Messaging/FIRMessaging+FIRApp.m | 1 + Firebase/Messaging/FIRMessaging.m | 7 ++++--- Firebase/Messaging/FIRMessaging_Private.h | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'Firebase/Messaging') diff --git a/Firebase/Messaging/FIRMessaging+FIRApp.m b/Firebase/Messaging/FIRMessaging+FIRApp.m index 58ae3af..d48a3b4 100644 --- a/Firebase/Messaging/FIRMessaging+FIRApp.m +++ b/Firebase/Messaging/FIRMessaging+FIRApp.m @@ -72,6 +72,7 @@ } self.fcmSenderID = [options.GCMSenderID copy]; + self.globalAutomaticDataCollectionEnabled = [app isAutomaticDataCollectionEnabled]; // Swizzle remote-notification-related methods (app delegate and UNUserNotificationCenter) if ([FIRMessagingRemoteNotificationsProxy canSwizzleMethods]) { diff --git a/Firebase/Messaging/FIRMessaging.m b/Firebase/Messaging/FIRMessaging.m index 339bd7d..6222420 100644 --- a/Firebase/Messaging/FIRMessaging.m +++ b/Firebase/Messaging/FIRMessaging.m @@ -75,7 +75,7 @@ NSString *const kFIRMessagingUserDefaultsKeyAutoInitEnabled = NSString *const kFIRMessagingAPNSTokenType = @"APNSTokenType"; // APNS Token type key stored in user info. -static NSString *const kFIRMessagingPlistAutoInitEnabled = +NSString *const kFIRMessagingPlistAutoInitEnabled = @"FirebaseMessagingAutoInitEnabled"; // Auto Init Enabled key stored in Info.plist @interface FIRMessagingMessageInfo () @@ -471,8 +471,9 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled = if (isAutoInitEnabledObject) { return [isAutoInitEnabledObject boolValue]; } - // If none of above exists, we default assume FCM auto init is enabled. - return YES; + + // If none of above exists, we default to the global switch that comes from FIRApp. + return self.isGlobalAutomaticDataCollectionEnabled; } - (void)setAutoInitEnabled:(BOOL)autoInitEnabled { diff --git a/Firebase/Messaging/FIRMessaging_Private.h b/Firebase/Messaging/FIRMessaging_Private.h index 46daee0..6bac99d 100644 --- a/Firebase/Messaging/FIRMessaging_Private.h +++ b/Firebase/Messaging/FIRMessaging_Private.h @@ -25,6 +25,7 @@ typedef NS_ENUM(int8_t, FIRMessagingNetworkStatus) { kFIRMessagingReachabilityReachableViaWWAN, }; +FOUNDATION_EXPORT NSString *const kFIRMessagingPlistAutoInitEnabled; FOUNDATION_EXPORT NSString *const kFIRMessagingUserDefaultsKeyAutoInitEnabled; @interface FIRMessagingRemoteMessage () @@ -37,6 +38,9 @@ FOUNDATION_EXPORT NSString *const kFIRMessagingUserDefaultsKeyAutoInitEnabled; #pragma mark - Private API +// The data collection flag from Core. +@property(nonatomic, readwrite, getter=isGlobalAutomaticDataCollectionEnabled) BOOL globalAutomaticDataCollectionEnabled; + - (NSString *)defaultFcmToken; - (FIRMessagingClient *)client; - (FIRMessagingPubSub *)pubsub; -- cgit v1.2.3