Skip to content
9 changes: 9 additions & 0 deletions Example/Messaging/Tests/FIRMessagingTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ - (void)testDoesAutomaticallyConnectIfTokenAvailableAndForegrounded {
// 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
Expand All @@ -186,7 +189,10 @@ - (void)testDoesNotAutomaticallyConnectIfTokenIsEmpty {
// 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];
Expand All @@ -203,7 +209,10 @@ - (void)testDoesNotAutomaticallyConnectIfApplicationNotActive {
// 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
Expand Down
3 changes: 3 additions & 0 deletions Example/Messaging/Tests/FIRMessagingTestUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ - (void)cleanupAfterTest:(XCTestCase *)testCase {
[_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];
Expand Down
8 changes: 5 additions & 3 deletions Firebase/Messaging/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
15 changes: 14 additions & 1 deletion Firebase/Messaging/FIRMessaging.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ - (instancetype)initWithStatus:(FIRMessagingMessageStatus)status {
@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];
Expand Down Expand Up @@ -666,9 +669,12 @@ - (void)notifyDelegateOfFCMTokenAvailability {
#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
Expand Down Expand Up @@ -730,7 +736,10 @@ - (void)updateAutomaticClientConnection {

- (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
Expand Down Expand Up @@ -867,11 +876,12 @@ + (NSString *)FIRMessagingSDKCurrentLocale {

#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
Expand Down Expand Up @@ -934,9 +944,12 @@ - (void)didReceiveDefaultInstanceIDToken:(NSNotification *)notification {
[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 {
Expand Down
3 changes: 3 additions & 0 deletions Firebase/Messaging/FIRMessagingReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 11 additions & 2 deletions Firebase/Messaging/FIRMessagingReceiver.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ - (void)willSendDataMessageWithID:(NSString *)messageID error:(NSError *)error {
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);
Expand All @@ -60,29 +63,35 @@ - (void)didSendDataMessageWithID:(NSString *)messageID {
// 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 {
Expand Down
38 changes: 22 additions & 16 deletions Firebase/Messaging/Public/FIRMessaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -83,15 +83,15 @@ 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
* an FCM socket connection. You can query the connection state in this
* 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -127,15 +127,15 @@ 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
* an FCM socket connection. You can query the connection state in this
* 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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

/**
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down