Skip to content

Commit 27c4898

Browse files
Deprecating FCM Direct Channel API (#4710)
1 parent d9b7a33 commit 27c4898

File tree

7 files changed

+67
-22
lines changed

7 files changed

+67
-22
lines changed

Example/Messaging/Tests/FIRMessagingTest.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ - (void)testDoesAutomaticallyConnectIfTokenAvailableAndForegrounded {
168168
// Doing nothing on purpose, when -updateAutomaticClientConnection is called
169169
}] updateAutomaticClientConnection];
170170
// Set direct channel to be established after disabling connection attempt
171+
#pragma clang diagnostic push
172+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
171173
self.messaging.shouldEstablishDirectChannel = YES;
174+
#pragma clang diagnostic pop
172175
// Set a "valid" token (i.e. not nil or empty)
173176
self.messaging.defaultFcmToken = @"1234567";
174177
// Swizzle application state to return UIApplicationStateActive
@@ -186,7 +189,10 @@ - (void)testDoesNotAutomaticallyConnectIfTokenIsEmpty {
186189
// Doing nothing on purpose, when -updateAutomaticClientConnection is called
187190
}] updateAutomaticClientConnection];
188191
// Set direct channel to be established after disabling connection attempt
192+
#pragma clang diagnostic push
193+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
189194
self.messaging.shouldEstablishDirectChannel = YES;
195+
#pragma clang diagnostic pop
190196
// By default, there should be no fcmToken
191197
// Swizzle application state to return UIApplicationStateActive
192198
UIApplication *app = [UIApplication sharedApplication];
@@ -203,7 +209,10 @@ - (void)testDoesNotAutomaticallyConnectIfApplicationNotActive {
203209
// Doing nothing on purpose, when -updateAutomaticClientConnection is called
204210
}] updateAutomaticClientConnection];
205211
// Set direct channel to be established after disabling connection attempt
212+
#pragma clang diagnostic push
213+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
206214
self.messaging.shouldEstablishDirectChannel = YES;
215+
#pragma clang diagnostic pop
207216
// Set a "valid" token (i.e. not nil or empty)
208217
self.messaging.defaultFcmToken = @"abcd1234";
209218
// Swizzle application state to return UIApplicationStateActive

Example/Messaging/Tests/FIRMessagingTestUtilities.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ - (void)cleanupAfterTest:(XCTestCase *)testCase {
123123
[_messaging.rmq2Manager removeDatabase];
124124
[testCase waitForDrainDatabaseQueueForRmqManager:_messaging.rmq2Manager];
125125
[_messaging.messagingUserDefaults removePersistentDomainForName:kFIRMessagingDefaultsTestDomain];
126+
#pragma clang diagnostic push
127+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
126128
_messaging.shouldEstablishDirectChannel = NO;
129+
#pragma clang diagnostic pop
127130
[_mockPubsub stopMocking];
128131
[_mockMessaging stopMocking];
129132
[_mockInstanceID stopMocking];

Firebase/Messaging/CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# unreleased
1+
# 2020-02 -- v4.3.0
2+
- [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)
3+
- [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)
24
- [fixed] Use secure coding for Messaging's pending topics. (#3686)
35

4-
# 2020-02 -- v 4.2.1
6+
# 2020-02 -- v4.2.1
57
- [added] Firebase Pod support for watchOS: `pod 'Firebase/Messaging'` in addition to `pod 'FirebaseMessaging'`. (#4807)
68
- [fixed] Fix FIRMessagingExtensionHelper crash in unit tests when `attachment == nil`. (#4689)
79
- [fixed] Fix FIRMessagingRmqManager crash when database is removed. This only happens when device has a corrupted database file. (#4771)
810

9-
# 2020-01 -- v 4.2.0
11+
# 2020-01 -- v4.2.0
1012
- [added] Added watchOS support for Firebase Messaging. This enables FCM push notification function on watch only app or independent watch app. (#4016)
1113
- [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).
1214

Firebase/Messaging/FIRMessaging.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ - (instancetype)initWithStatus:(FIRMessagingMessageStatus)status {
122122
@end
123123

124124
#pragma mark - for iOS 10 compatibility
125+
#pragma clang diagnostic push
126+
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
125127
@implementation FIRMessagingRemoteMessage
128+
#pragma clang diagnostic pop
126129

127130
- (instancetype)init {
128131
self = [super init];
@@ -666,9 +669,12 @@ - (void)notifyDelegateOfFCMTokenAvailability {
666669
#pragma mark - Application State Changes
667670

668671
- (void)applicationStateChanged {
672+
#pragma clang diagnostic push
673+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
669674
if (self.shouldEstablishDirectChannel) {
670675
[self updateAutomaticClientConnection];
671676
}
677+
#pragma clang diagnostic pop
672678
}
673679

674680
#pragma mark - Direct Channel
@@ -730,7 +736,10 @@ - (void)updateAutomaticClientConnection {
730736

731737
- (void)notifyOfDirectChannelConnectionChange {
732738
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
739+
#pragma clang diagnostic push
740+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
733741
[center postNotificationName:FIRMessagingConnectionStateChangedNotification object:self];
742+
#pragma clang diagnostic pop
734743
}
735744

736745
#pragma mark - Topics
@@ -867,11 +876,12 @@ + (NSString *)FIRMessagingSDKCurrentLocale {
867876

868877
#pragma mark - FIRMessagingReceiverDelegate
869878

879+
#pragma clang diagnostic push
880+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
870881
- (void)receiver:(FIRMessagingReceiver *)receiver
871882
receivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
872883
if ([self.delegate respondsToSelector:@selector(messaging:didReceiveMessage:)]) {
873884
[self appDidReceiveMessage:remoteMessage.appData];
874-
#pragma clang diagnostic push
875885
#pragma clang diagnostic ignored "-Wunguarded-availability"
876886
[self.delegate messaging:self didReceiveMessage:remoteMessage];
877887
#pragma clang diagnostic pop
@@ -934,9 +944,12 @@ - (void)didReceiveDefaultInstanceIDToken:(NSNotification *)notification {
934944
[self notifyDelegateOfFCMTokenAvailability];
935945
}
936946
[self.pubsub scheduleSync:YES];
947+
#pragma clang diagnostic push
948+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
937949
if (self.shouldEstablishDirectChannel) {
938950
[self updateAutomaticClientConnection];
939951
}
952+
#pragma clang diagnostic pop
940953
}
941954

942955
- (void)defaultInstanceIDTokenWasRefreshed:(NSNotification *)notification {

Firebase/Messaging/FIRMessagingReceiver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ NS_ASSUME_NONNULL_BEGIN
2222
@class FIRMessagingReceiver;
2323
@protocol FIRMessagingReceiverDelegate <NSObject>
2424

25+
#pragma clang diagnostic push
26+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
2527
- (void)receiver:(FIRMessagingReceiver *)receiver
2628
receivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage;
29+
#pragma clang diagnostic pop
2730

2831
@end
2932

Firebase/Messaging/FIRMessagingReceiver.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ - (void)willSendDataMessageWithID:(NSString *)messageID error:(NSError *)error {
4444
if (error) {
4545
NSDictionary *userInfo =
4646
@{kUpstreamMessageIDUserInfoKey : [messageID copy], kUpstreamErrorUserInfoKey : error};
47+
#pragma clang diagnostic push
48+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
4749
notification = [NSNotification notificationWithName:FIRMessagingSendErrorNotification
4850
object:nil
4951
userInfo:userInfo];
52+
#pragma clang diagnostic pop
5053
[[NSNotificationQueue defaultQueue] enqueueNotification:notification postingStyle:NSPostASAP];
5154
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeReceiver000,
5255
@"Fail to send upstream message: %@ error: %@", messageID, error);
@@ -60,29 +63,35 @@ - (void)didSendDataMessageWithID:(NSString *)messageID {
6063
// invoke the callbacks asynchronously
6164
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeReceiver002, @"Did send upstream message: %@",
6265
messageID);
66+
#pragma clang diagnostic push
67+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
6368
NSNotification *notification =
6469
[NSNotification notificationWithName:FIRMessagingSendSuccessNotification
6570
object:nil
6671
userInfo:@{kUpstreamMessageIDUserInfoKey : [messageID copy]}];
67-
72+
#pragma clang diagnostic pop
6873
[[NSNotificationQueue defaultQueue] enqueueNotification:notification postingStyle:NSPostASAP];
6974
}
7075

7176
- (void)didDeleteMessagesOnServer {
7277
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeReceiver003,
7378
@"Will send deleted messages notification");
79+
#pragma clang diagnostic push
80+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
7481
NSNotification *notification =
7582
[NSNotification notificationWithName:FIRMessagingMessagesDeletedNotification object:nil];
76-
7783
[[NSNotificationQueue defaultQueue] enqueueNotification:notification postingStyle:NSPostASAP];
7884
}
7985

8086
#pragma mark - Private Helpers
8187
- (void)handleDirectChannelMessage:(NSDictionary *)message withIdentifier:(NSString *)messageID {
88+
#pragma clang diagnostic push
89+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
8290
FIRMessagingRemoteMessage *wrappedMessage = [[FIRMessagingRemoteMessage alloc] init];
8391
wrappedMessage.appData = [message copy];
8492
wrappedMessage.messageID = messageID;
8593
[self.delegate receiver:self receivedRemoteMessage:wrappedMessage];
94+
#pragma clang diagnostic pop
8695
}
8796

8897
+ (NSString *)nextMessageID {

Firebase/Messaging/Public/FIRMessaging.h

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef void (^FIRMessagingTopicOperationCompletion)(NSError *_Nullable error);
6363
* of the successfully delivered message.
6464
*/
6565
FOUNDATION_EXPORT const NSNotificationName FIRMessagingSendSuccessNotification
66-
NS_SWIFT_NAME(MessagingSendSuccess);
66+
NS_SWIFT_NAME(MessagingSendSuccess) DEPRECATED_ATTRIBUTE;
6767

6868
/**
6969
* Notification sent when the upstream message was failed to be sent to the
@@ -72,7 +72,7 @@ FOUNDATION_EXPORT const NSNotificationName FIRMessagingSendSuccessNotification
7272
* information for the failure.
7373
*/
7474
FOUNDATION_EXPORT const NSNotificationName FIRMessagingSendErrorNotification
75-
NS_SWIFT_NAME(MessagingSendError);
75+
NS_SWIFT_NAME(MessagingSendError) DEPRECATED_ATTRIBUTE;
7676

7777
/**
7878
* Notification sent when the Firebase messaging server deletes pending
@@ -83,15 +83,15 @@ FOUNDATION_EXPORT const NSNotificationName FIRMessagingSendErrorNotification
8383
* server.
8484
*/
8585
FOUNDATION_EXPORT const NSNotificationName FIRMessagingMessagesDeletedNotification
86-
NS_SWIFT_NAME(MessagingMessagesDeleted);
86+
NS_SWIFT_NAME(MessagingMessagesDeleted) DEPRECATED_ATTRIBUTE;
8787

8888
/**
8989
* Notification sent when Firebase Messaging establishes or disconnects from
9090
* an FCM socket connection. You can query the connection state in this
9191
* notification by checking the `isDirectChannelEstablished` property of FIRMessaging.
9292
*/
9393
FOUNDATION_EXPORT const NSNotificationName FIRMessagingConnectionStateChangedNotification
94-
NS_SWIFT_NAME(MessagingConnectionStateChanged);
94+
NS_SWIFT_NAME(MessagingConnectionStateChanged) DEPRECATED_ATTRIBUTE;
9595

9696
/**
9797
* Notification sent when the FCM registration token has been refreshed. Please use the
@@ -107,7 +107,7 @@ FOUNDATION_EXPORT const NSNotificationName FIRMessagingRegistrationTokenRefreshe
107107
* of the successfully delivered message.
108108
*/
109109
FOUNDATION_EXPORT NSString *const FIRMessagingSendSuccessNotification
110-
NS_SWIFT_NAME(MessagingSendSuccessNotification);
110+
NS_SWIFT_NAME(MessagingSendSuccessNotification) DEPRECATED_ATTRIBUTE;
111111

112112
/**
113113
* Notification sent when the upstream message was failed to be sent to the
@@ -116,7 +116,7 @@ FOUNDATION_EXPORT NSString *const FIRMessagingSendSuccessNotification
116116
* information for the failure.
117117
*/
118118
FOUNDATION_EXPORT NSString *const FIRMessagingSendErrorNotification
119-
NS_SWIFT_NAME(MessagingSendErrorNotification);
119+
NS_SWIFT_NAME(MessagingSendErrorNotification) DEPRECATED_ATTRIBUTE;
120120

121121
/**
122122
* Notification sent when the Firebase messaging server deletes pending
@@ -127,15 +127,15 @@ FOUNDATION_EXPORT NSString *const FIRMessagingSendErrorNotification
127127
* server.
128128
*/
129129
FOUNDATION_EXPORT NSString *const FIRMessagingMessagesDeletedNotification
130-
NS_SWIFT_NAME(MessagingMessagesDeletedNotification);
130+
NS_SWIFT_NAME(MessagingMessagesDeletedNotification) DEPRECATED_ATTRIBUTE;
131131

132132
/**
133133
* Notification sent when Firebase Messaging establishes or disconnects from
134134
* an FCM socket connection. You can query the connection state in this
135135
* notification by checking the `isDirectChannelEstablished` property of FIRMessaging.
136136
*/
137137
FOUNDATION_EXPORT NSString *const FIRMessagingConnectionStateChangedNotification
138-
NS_SWIFT_NAME(MessagingConnectionStateChangedNotification);
138+
NS_SWIFT_NAME(MessagingConnectionStateChangedNotification) DEPRECATED_ATTRIBUTE;
139139

140140
/**
141141
* Notification sent when the FCM registration token has been refreshed. Please use the
@@ -216,12 +216,14 @@ NS_SWIFT_NAME(MessagingMessageInfo)
216216
* the local and remote notifications handlers defined in UIApplicationDelegate protocol.
217217
*/
218218
NS_SWIFT_NAME(MessagingRemoteMessage)
219-
@interface FIRMessagingRemoteMessage : NSObject
219+
__deprecated_msg(
220+
"FCM direct channel is deprecated, please use APNs for downstream message handling.")
221+
@interface FIRMessagingRemoteMessage : NSObject
220222

221223
/// The message ID of downstream message.
222-
@property(nonatomic, readonly, copy) NSString *messageID;
224+
@property(nonatomic, readonly, copy) NSString *messageID DEPRECATED_ATTRIBUTE;
223225
/// The downstream message received by the application.
224-
@property(nonatomic, readonly, strong) NSDictionary *appData;
226+
@property(nonatomic, readonly, strong) NSDictionary *appData DEPRECATED_ATTRIBUTE;
225227

226228
@end
227229

@@ -250,8 +252,8 @@ NS_SWIFT_NAME(MessagingDelegate)
250252
/// Handle data messages received via FCM direct channel (not via APNS).
251253
- (void)messaging:(FIRMessaging *)messaging
252254
didReceiveMessage:(FIRMessagingRemoteMessage *)remoteMessage
253-
NS_SWIFT_NAME(messaging(_:didReceive:));
254-
255+
NS_SWIFT_NAME(messaging(_:didReceive:))__deprecated_msg(
256+
"FCM direct channel is deprecated, please use APNs for downstream message handling.");
255257
@end
256258

257259
/**
@@ -278,12 +280,14 @@ NS_SWIFT_NAME(Messaging)
278280
* receiving non-APNS, data-only messages in foregrounded apps.
279281
* Default is `NO`.
280282
*/
281-
@property(nonatomic) BOOL shouldEstablishDirectChannel;
283+
@property(nonatomic) BOOL shouldEstablishDirectChannel DEPRECATED_MSG_ATTRIBUTE(
284+
"FCM direct channel is deprecated, please use APNs channel for downstream message delivery.");
282285

283286
/**
284287
* Returns `YES` if the direct channel to the FCM server is active, and `NO` otherwise.
285288
*/
286-
@property(nonatomic, readonly) BOOL isDirectChannelEstablished;
289+
@property(nonatomic, readonly) BOOL isDirectChannelEstablished DEPRECATED_MSG_ATTRIBUTE(
290+
"FCM direct channel is deprecated, please use APNs channel for downstream message delivery.");
287291

288292
/**
289293
* FIRMessaging
@@ -480,7 +484,9 @@ NS_SWIFT_NAME(Messaging)
480484
- (void)sendMessage:(NSDictionary *)message
481485
to:(NSString *)receiver
482486
withMessageID:(NSString *)messageID
483-
timeToLive:(int64_t)ttl;
487+
timeToLive:(int64_t)ttl
488+
__deprecated_msg("Upstream messaging through direct channel is deprecated. For realtime "
489+
"updates, use Cloud Firestore, Realtime Database, or other services. ");
484490

485491
#pragma mark - Analytics
486492

0 commit comments

Comments
 (0)