Преглед изворни кода

Deprecating FCM Direct Channel API (#4710)

Chen Liang пре 6 година
родитељ
комит
27c4898cec

+ 9 - 0
Example/Messaging/Tests/FIRMessagingTest.m

@@ -168,7 +168,10 @@ static NSString *const kFIRMessagingDefaultsTestDomain = @"com.messaging.tests";
       // Doing nothing on purpose, when -updateAutomaticClientConnection is called
   }] updateAutomaticClientConnection];
   // Set direct channel to be established after disabling connection attempt
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   self.messaging.shouldEstablishDirectChannel = YES;
+#pragma clang diagnostic pop
   // Set a "valid" token (i.e. not nil or empty)
   self.messaging.defaultFcmToken = @"1234567";
   // Swizzle application state to return UIApplicationStateActive
@@ -186,7 +189,10 @@ static NSString *const kFIRMessagingDefaultsTestDomain = @"com.messaging.tests";
       // Doing nothing on purpose, when -updateAutomaticClientConnection is called
   }] updateAutomaticClientConnection];
   // Set direct channel to be established after disabling connection attempt
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   self.messaging.shouldEstablishDirectChannel = YES;
+#pragma clang diagnostic pop
   // By default, there should be no fcmToken
   // Swizzle application state to return UIApplicationStateActive
   UIApplication *app = [UIApplication sharedApplication];
@@ -203,7 +209,10 @@ static NSString *const kFIRMessagingDefaultsTestDomain = @"com.messaging.tests";
       // Doing nothing on purpose, when -updateAutomaticClientConnection is called
   }] updateAutomaticClientConnection];
   // Set direct channel to be established after disabling connection attempt
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   self.messaging.shouldEstablishDirectChannel = YES;
+#pragma clang diagnostic pop
   // Set a "valid" token (i.e. not nil or empty)
   self.messaging.defaultFcmToken = @"abcd1234";
   // Swizzle application state to return UIApplicationStateActive

+ 3 - 0
Example/Messaging/Tests/FIRMessagingTestUtilities.m

@@ -123,7 +123,10 @@ static NSString *const kFIRMessagingDefaultsTestDomain = @"com.messaging.tests";
   [_messaging.rmq2Manager removeDatabase];
   [testCase waitForDrainDatabaseQueueForRmqManager:_messaging.rmq2Manager];
   [_messaging.messagingUserDefaults removePersistentDomainForName:kFIRMessagingDefaultsTestDomain];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   _messaging.shouldEstablishDirectChannel = NO;
+#pragma clang diagnostic pop
   [_mockPubsub stopMocking];
   [_mockMessaging stopMocking];
   [_mockInstanceID stopMocking];

+ 5 - 3
Firebase/Messaging/CHANGELOG.md

@@ -1,12 +1,14 @@
-# unreleased
+# 2020-02 -- v4.3.0
+- [changed] Deprecated FCM direct channel messaging via `shouldEstablishDirectChannel`. Instead, use APNs for downstream message delivery. Add `content_available` key to your payload if you want to continue use legacy APIs, but we strongly recommend HTTP v1 API as it provides full APNs support. The deprecated API will be removed in Firebase 7. (#4710)
+- [changed] Deprecated upstream messaging API. For realtime updates, use Cloud Firestore, Realtime Database, or other services. The deprecated API will be removed in Firebase 7. (#4710)
 - [fixed] Use secure coding for Messaging's pending topics. (#3686)
 
-# 2020-02 -- v 4.2.1
+# 2020-02 -- v4.2.1
 - [added] Firebase Pod support for watchOS: `pod 'Firebase/Messaging'` in addition to `pod 'FirebaseMessaging'`. (#4807)
 - [fixed] Fix FIRMessagingExtensionHelper crash in unit tests when `attachment == nil`. (#4689)
 - [fixed] Fix FIRMessagingRmqManager crash when database is removed. This only happens when device has a corrupted database file. (#4771)
 
-# 2020-01 -- v 4.2.0
+# 2020-01 -- v4.2.0
 - [added] Added watchOS support for Firebase Messaging. This enables FCM push notification function on watch only app or independent watch app. (#4016)
 - [added] Added a new transitive dependency on the [Firebase Installations SDK](../../FirebaseInstallations/CHANGELOG.md). The Firebase Installations SDK introduces the [Firebase Installations API](https://console.cloud.google.com/apis/library/firebaseinstallations.googleapis.com). Developers that use API-restrictions for their API-Keys may experience blocked requests (https://stackoverflow.com/questions/58495985/). A solution is available [here](../../FirebaseInstallations/API_KEY_RESTRICTIONS.md).
 

+ 14 - 1
Firebase/Messaging/FIRMessaging.m

@@ -122,7 +122,10 @@ BOOL FIRMessagingIsContextManagerMessage(NSDictionary *message) {
 @end
 
 #pragma mark - for iOS 10 compatibility
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-implementations"
 @implementation FIRMessagingRemoteMessage
+#pragma clang diagnostic pop
 
 - (instancetype)init {
   self = [super init];
@@ -666,9 +669,12 @@ BOOL FIRMessagingIsContextManagerMessage(NSDictionary *message) {
 #pragma mark - Application State Changes
 
 - (void)applicationStateChanged {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   if (self.shouldEstablishDirectChannel) {
     [self updateAutomaticClientConnection];
   }
+#pragma clang diagnostic pop
 }
 
 #pragma mark - Direct Channel
@@ -730,7 +736,10 @@ BOOL FIRMessagingIsContextManagerMessage(NSDictionary *message) {
 
 - (void)notifyOfDirectChannelConnectionChange {
   NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   [center postNotificationName:FIRMessagingConnectionStateChangedNotification object:self];
+#pragma clang diagnostic pop
 }
 
 #pragma mark - Topics
@@ -867,11 +876,12 @@ BOOL FIRMessagingIsContextManagerMessage(NSDictionary *message) {
 
 #pragma mark - FIRMessagingReceiverDelegate
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
 - (void)receiver:(FIRMessagingReceiver *)receiver
     receivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
   if ([self.delegate respondsToSelector:@selector(messaging:didReceiveMessage:)]) {
     [self appDidReceiveMessage:remoteMessage.appData];
-#pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunguarded-availability"
     [self.delegate messaging:self didReceiveMessage:remoteMessage];
 #pragma clang diagnostic pop
@@ -934,9 +944,12 @@ BOOL FIRMessagingIsContextManagerMessage(NSDictionary *message) {
     [self notifyDelegateOfFCMTokenAvailability];
   }
   [self.pubsub scheduleSync:YES];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   if (self.shouldEstablishDirectChannel) {
     [self updateAutomaticClientConnection];
   }
+#pragma clang diagnostic pop
 }
 
 - (void)defaultInstanceIDTokenWasRefreshed:(NSNotification *)notification {

+ 3 - 0
Firebase/Messaging/FIRMessagingReceiver.h

@@ -22,8 +22,11 @@ NS_ASSUME_NONNULL_BEGIN
 @class FIRMessagingReceiver;
 @protocol FIRMessagingReceiverDelegate <NSObject>
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
 - (void)receiver:(FIRMessagingReceiver *)receiver
     receivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage;
+#pragma clang diagnostic pop
 
 @end
 

+ 11 - 2
Firebase/Messaging/FIRMessagingReceiver.m

@@ -44,9 +44,12 @@ static int downstreamMessageID = 0;
   if (error) {
     NSDictionary *userInfo =
         @{kUpstreamMessageIDUserInfoKey : [messageID copy], kUpstreamErrorUserInfoKey : error};
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
     notification = [NSNotification notificationWithName:FIRMessagingSendErrorNotification
                                                  object:nil
                                                userInfo:userInfo];
+#pragma clang diagnostic pop
     [[NSNotificationQueue defaultQueue] enqueueNotification:notification postingStyle:NSPostASAP];
     FIRMessagingLoggerDebug(kFIRMessagingMessageCodeReceiver000,
                             @"Fail to send upstream message: %@ error: %@", messageID, error);
@@ -60,29 +63,35 @@ static int downstreamMessageID = 0;
   // invoke the callbacks asynchronously
   FIRMessagingLoggerDebug(kFIRMessagingMessageCodeReceiver002, @"Did send upstream message: %@",
                           messageID);
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   NSNotification *notification =
       [NSNotification notificationWithName:FIRMessagingSendSuccessNotification
                                     object:nil
                                   userInfo:@{kUpstreamMessageIDUserInfoKey : [messageID copy]}];
-
+#pragma clang diagnostic pop
   [[NSNotificationQueue defaultQueue] enqueueNotification:notification postingStyle:NSPostASAP];
 }
 
 - (void)didDeleteMessagesOnServer {
   FIRMessagingLoggerDebug(kFIRMessagingMessageCodeReceiver003,
                           @"Will send deleted messages notification");
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   NSNotification *notification =
       [NSNotification notificationWithName:FIRMessagingMessagesDeletedNotification object:nil];
-
   [[NSNotificationQueue defaultQueue] enqueueNotification:notification postingStyle:NSPostASAP];
 }
 
 #pragma mark - Private Helpers
 - (void)handleDirectChannelMessage:(NSDictionary *)message withIdentifier:(NSString *)messageID {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
   FIRMessagingRemoteMessage *wrappedMessage = [[FIRMessagingRemoteMessage alloc] init];
   wrappedMessage.appData = [message copy];
   wrappedMessage.messageID = messageID;
   [self.delegate receiver:self receivedRemoteMessage:wrappedMessage];
+#pragma clang diagnostic pop
 }
 
 + (NSString *)nextMessageID {

+ 22 - 16
Firebase/Messaging/Public/FIRMessaging.h

@@ -63,7 +63,7 @@ typedef void (^FIRMessagingTopicOperationCompletion)(NSError *_Nullable error);
  *  of the successfully delivered message.
  */
 FOUNDATION_EXPORT const NSNotificationName FIRMessagingSendSuccessNotification
-    NS_SWIFT_NAME(MessagingSendSuccess);
+    NS_SWIFT_NAME(MessagingSendSuccess) DEPRECATED_ATTRIBUTE;
 
 /**
  *  Notification sent when the upstream message was failed to be sent to the
@@ -72,7 +72,7 @@ FOUNDATION_EXPORT const NSNotificationName FIRMessagingSendSuccessNotification
  *  information for the failure.
  */
 FOUNDATION_EXPORT const NSNotificationName FIRMessagingSendErrorNotification
-    NS_SWIFT_NAME(MessagingSendError);
+    NS_SWIFT_NAME(MessagingSendError) DEPRECATED_ATTRIBUTE;
 
 /**
  *  Notification sent when the Firebase messaging server deletes pending
@@ -83,7 +83,7 @@ FOUNDATION_EXPORT const NSNotificationName FIRMessagingSendErrorNotification
  *  server.
  */
 FOUNDATION_EXPORT const NSNotificationName FIRMessagingMessagesDeletedNotification
-    NS_SWIFT_NAME(MessagingMessagesDeleted);
+    NS_SWIFT_NAME(MessagingMessagesDeleted) DEPRECATED_ATTRIBUTE;
 
 /**
  *  Notification sent when Firebase Messaging establishes or disconnects from
@@ -91,7 +91,7 @@ FOUNDATION_EXPORT const NSNotificationName FIRMessagingMessagesDeletedNotificati
  *  notification by checking the `isDirectChannelEstablished` property of FIRMessaging.
  */
 FOUNDATION_EXPORT const NSNotificationName FIRMessagingConnectionStateChangedNotification
-    NS_SWIFT_NAME(MessagingConnectionStateChanged);
+    NS_SWIFT_NAME(MessagingConnectionStateChanged) DEPRECATED_ATTRIBUTE;
 
 /**
  *  Notification sent when the FCM registration token has been refreshed. Please use the
@@ -107,7 +107,7 @@ FOUNDATION_EXPORT const NSNotificationName FIRMessagingRegistrationTokenRefreshe
  *  of the successfully delivered message.
  */
 FOUNDATION_EXPORT NSString *const FIRMessagingSendSuccessNotification
-    NS_SWIFT_NAME(MessagingSendSuccessNotification);
+    NS_SWIFT_NAME(MessagingSendSuccessNotification) DEPRECATED_ATTRIBUTE;
 
 /**
  *  Notification sent when the upstream message was failed to be sent to the
@@ -116,7 +116,7 @@ FOUNDATION_EXPORT NSString *const FIRMessagingSendSuccessNotification
  *  information for the failure.
  */
 FOUNDATION_EXPORT NSString *const FIRMessagingSendErrorNotification
-    NS_SWIFT_NAME(MessagingSendErrorNotification);
+    NS_SWIFT_NAME(MessagingSendErrorNotification) DEPRECATED_ATTRIBUTE;
 
 /**
  *  Notification sent when the Firebase messaging server deletes pending
@@ -127,7 +127,7 @@ FOUNDATION_EXPORT NSString *const FIRMessagingSendErrorNotification
  *  server.
  */
 FOUNDATION_EXPORT NSString *const FIRMessagingMessagesDeletedNotification
-    NS_SWIFT_NAME(MessagingMessagesDeletedNotification);
+    NS_SWIFT_NAME(MessagingMessagesDeletedNotification) DEPRECATED_ATTRIBUTE;
 
 /**
  *  Notification sent when Firebase Messaging establishes or disconnects from
@@ -135,7 +135,7 @@ FOUNDATION_EXPORT NSString *const FIRMessagingMessagesDeletedNotification
  *  notification by checking the `isDirectChannelEstablished` property of FIRMessaging.
  */
 FOUNDATION_EXPORT NSString *const FIRMessagingConnectionStateChangedNotification
-    NS_SWIFT_NAME(MessagingConnectionStateChangedNotification);
+    NS_SWIFT_NAME(MessagingConnectionStateChangedNotification) DEPRECATED_ATTRIBUTE;
 
 /**
  *  Notification sent when the FCM registration token has been refreshed. Please use the
@@ -216,12 +216,14 @@ NS_SWIFT_NAME(MessagingMessageInfo)
  * the local and remote notifications handlers defined in UIApplicationDelegate protocol.
  */
 NS_SWIFT_NAME(MessagingRemoteMessage)
-@interface FIRMessagingRemoteMessage : NSObject
+__deprecated_msg(
+    "FCM direct channel is deprecated, please use APNs for downstream message handling.")
+    @interface FIRMessagingRemoteMessage : NSObject
 
 /// The message ID of downstream message.
-@property(nonatomic, readonly, copy) NSString *messageID;
+@property(nonatomic, readonly, copy) NSString *messageID DEPRECATED_ATTRIBUTE;
 /// The downstream message received by the application.
-@property(nonatomic, readonly, strong) NSDictionary *appData;
+@property(nonatomic, readonly, strong) NSDictionary *appData DEPRECATED_ATTRIBUTE;
 
 @end
 
@@ -250,8 +252,8 @@ NS_SWIFT_NAME(MessagingDelegate)
 /// Handle data messages received via FCM direct channel (not via APNS).
 - (void)messaging:(FIRMessaging *)messaging
     didReceiveMessage:(FIRMessagingRemoteMessage *)remoteMessage
-    NS_SWIFT_NAME(messaging(_:didReceive:));
-
+    NS_SWIFT_NAME(messaging(_:didReceive:))__deprecated_msg(
+        "FCM direct channel is deprecated, please use APNs for downstream message handling.");
 @end
 
 /**
@@ -278,12 +280,14 @@ NS_SWIFT_NAME(Messaging)
  *  receiving non-APNS, data-only messages in foregrounded apps.
  *  Default is `NO`.
  */
-@property(nonatomic) BOOL shouldEstablishDirectChannel;
+@property(nonatomic) BOOL shouldEstablishDirectChannel DEPRECATED_MSG_ATTRIBUTE(
+    "FCM direct channel is deprecated, please use APNs channel for downstream message delivery.");
 
 /**
  *  Returns `YES` if the direct channel to the FCM server is active, and `NO` otherwise.
  */
-@property(nonatomic, readonly) BOOL isDirectChannelEstablished;
+@property(nonatomic, readonly) BOOL isDirectChannelEstablished DEPRECATED_MSG_ATTRIBUTE(
+    "FCM direct channel is deprecated, please use APNs channel for downstream message delivery.");
 
 /**
  *  FIRMessaging
@@ -480,7 +484,9 @@ NS_SWIFT_NAME(Messaging)
 - (void)sendMessage:(NSDictionary *)message
                  to:(NSString *)receiver
       withMessageID:(NSString *)messageID
-         timeToLive:(int64_t)ttl;
+         timeToLive:(int64_t)ttl
+    __deprecated_msg("Upstream messaging through direct channel is deprecated. For realtime "
+                     "updates, use Cloud Firestore, Realtime Database, or other services. ");
 
 #pragma mark - Analytics