Skip to content

Commit ec23996

Browse files
Remove useMessagingDelegateForDirectChannel property (#2711)
1 parent 54c95ee commit ec23996

File tree

12 files changed

+48
-734
lines changed

12 files changed

+48
-734
lines changed

Example/Firebase.xcodeproj/project.pbxproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
511DD29D2225C8C40094D78D /* FIRMessagingLinkHandlingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DE9315CC1E8738B70083EDBF /* FIRMessagingLinkHandlingTest.m */; };
138138
511DD29E2225C8C40094D78D /* FIRMessagingPendingTopicsListTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DE9315CD1E8738B70083EDBF /* FIRMessagingPendingTopicsListTest.m */; };
139139
511DD29F2225C8C40094D78D /* FIRMessagingPubSubTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DE9315CE1E8738B70083EDBF /* FIRMessagingPubSubTest.m */; };
140-
511DD2A02225C8C40094D78D /* FIRMessagingReceiverTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DEF61BFC216E8B1000A738D4 /* FIRMessagingReceiverTest.m */; };
141140
511DD2A12225C8C40094D78D /* FIRMessagingRegistrarTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DE9315CF1E8738B70083EDBF /* FIRMessagingRegistrarTest.m */; };
142141
511DD2A22225C8C40094D78D /* FIRMessagingRemoteNotificationsProxyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DE9315D01E8738B70083EDBF /* FIRMessagingRemoteNotificationsProxyTest.m */; };
143142
511DD2A32225C8C40094D78D /* FIRMessagingRmqManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DE9315D11E8738B70083EDBF /* FIRMessagingRmqManagerTest.m */; };
@@ -635,7 +634,6 @@
635634
DEE14D931E84468D006FA992 /* FIROptionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DEE14D7A1E844677006FA992 /* FIROptionsTest.m */; };
636635
DEE14D941E84468D006FA992 /* FIRTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = DEE14D7C1E844677006FA992 /* FIRTestCase.m */; };
637636
DEF288411F9AB6E100D480CF /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = DEF288401F9AB6E100D480CF /* Default-568h@2x.png */; };
638-
DEF61BFD216E8B1100A738D4 /* FIRMessagingReceiverTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DEF61BFC216E8B1000A738D4 /* FIRMessagingReceiverTest.m */; };
639637
DEF6C30D1FBCE72F005D0740 /* FIRAuthDispatcherTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE9314FF1E86C6FF0083EDBF /* FIRAuthDispatcherTests.m */; };
640638
DEF6C30F1FBCE775005D0740 /* FIRAdditionalUserInfoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE9314FA1E86C6FF0083EDBF /* FIRAdditionalUserInfoTests.m */; };
641639
DEF6C3101FBCE775005D0740 /* FIRApp+FIRAuthUnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE9314FC1E86C6FF0083EDBF /* FIRApp+FIRAuthUnitTests.m */; };
@@ -1478,7 +1476,6 @@
14781476
DEE14D7C1E844677006FA992 /* FIRTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRTestCase.m; sourceTree = "<group>"; };
14791477
DEE14D7D1E844677006FA992 /* Tests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = "<group>"; };
14801478
DEF288401F9AB6E100D480CF /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
1481-
DEF61BFC216E8B1000A738D4 /* FIRMessagingReceiverTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRMessagingReceiverTest.m; sourceTree = "<group>"; };
14821479
E2C2834C90DBAB56D568189F /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
14831480
ED34CF4A20DC16DC000EA5D1 /* FIRComponentContainerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRComponentContainerTest.m; sourceTree = "<group>"; };
14841481
ED34CF4B20DC16DC000EA5D1 /* FIRTestComponents.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRTestComponents.m; sourceTree = "<group>"; };
@@ -2557,7 +2554,6 @@
25572554
DE9315CC1E8738B70083EDBF /* FIRMessagingLinkHandlingTest.m */,
25582555
DE9315CD1E8738B70083EDBF /* FIRMessagingPendingTopicsListTest.m */,
25592556
DE9315CE1E8738B70083EDBF /* FIRMessagingPubSubTest.m */,
2560-
DEF61BFC216E8B1000A738D4 /* FIRMessagingReceiverTest.m */,
25612557
DE9315CF1E8738B70083EDBF /* FIRMessagingRegistrarTest.m */,
25622558
DE9315D01E8738B70083EDBF /* FIRMessagingRemoteNotificationsProxyTest.m */,
25632559
DE9315D11E8738B70083EDBF /* FIRMessagingRmqManagerTest.m */,
@@ -4319,7 +4315,6 @@
43194315
511DD29D2225C8C40094D78D /* FIRMessagingLinkHandlingTest.m in Sources */,
43204316
511DD29E2225C8C40094D78D /* FIRMessagingPendingTopicsListTest.m in Sources */,
43214317
511DD29F2225C8C40094D78D /* FIRMessagingPubSubTest.m in Sources */,
4322-
511DD2A02225C8C40094D78D /* FIRMessagingReceiverTest.m in Sources */,
43234318
511DD2A12225C8C40094D78D /* FIRMessagingRegistrarTest.m in Sources */,
43244319
511DD2A22225C8C40094D78D /* FIRMessagingRemoteNotificationsProxyTest.m in Sources */,
43254320
511DD2A32225C8C40094D78D /* FIRMessagingRmqManagerTest.m in Sources */,
@@ -4941,7 +4936,6 @@
49414936
EDF5242C21EA37AA00BB24C6 /* FIRMessagingTestUtilities.m in Sources */,
49424937
DE9316031E8738E60083EDBF /* FIRMessagingSyncMessageManagerTest.m in Sources */,
49434938
DE9315FF1E8738E60083EDBF /* FIRMessagingRemoteNotificationsProxyTest.m in Sources */,
4944-
DEF61BFD216E8B1100A738D4 /* FIRMessagingReceiverTest.m in Sources */,
49454939
DE9315F81E8738E60083EDBF /* FIRMessagingDataMessageManagerTest.m in Sources */,
49464940
51284D16224ABD6A00274321 /* FIRMessagingExtensionHelperTest.m in Sources */,
49474941
DE9316051E8738E60083EDBF /* FIRMessagingTestNotificationUtilities.m in Sources */,

Example/Messaging/Tests/FIRMessagingReceiverTest.m

Lines changed: 0 additions & 75 deletions
This file was deleted.

Firebase/Messaging/FIRMessaging.m

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ - (void)setupNotificationListeners {
319319
}
320320

321321
- (void)setupReceiver {
322-
self.receiver = [[FIRMessagingReceiver alloc] initWithUserDefaults:self.messagingUserDefaults];
322+
self.receiver = [[FIRMessagingReceiver alloc] init];
323323
self.receiver.delegate = self;
324324
}
325325

@@ -659,15 +659,6 @@ - (void)notifyDelegateOfFCMTokenAvailability {
659659
}
660660
}
661661

662-
663-
- (void)setUseMessagingDelegateForDirectChannel:(BOOL)useMessagingDelegateForDirectChannel {
664-
self.receiver.useDirectChannel = useMessagingDelegateForDirectChannel;
665-
}
666-
667-
- (BOOL)useMessagingDelegateForDirectChannel {
668-
return self.receiver.useDirectChannel;
669-
}
670-
671662
#pragma mark - Application State Changes
672663

673664
- (void)applicationStateChanged {

Firebase/Messaging/FIRMessagingReceiver.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
3030

3131
@interface FIRMessagingReceiver : NSObject <FIRMessagingDataMessageManagerDelegate>
3232

33-
/// Default initializer for creating the messaging receiver.
34-
- (instancetype)initWithUserDefaults:(GULUserDefaults *)defaults NS_DESIGNATED_INITIALIZER;
35-
36-
/// Use `initWithUserDefaults:` instead.
37-
- (instancetype)init NS_UNAVAILABLE;
38-
3933
@property(nonatomic, weak, nullable) id<FIRMessagingReceiverDelegate> delegate;
40-
/// Whether to use direct channel for direct channel message callback handler in all iOS versions.
41-
@property(nonatomic, assign) BOOL useDirectChannel;
4234

4335
@end
4436

Firebase/Messaging/FIRMessagingReceiver.m

Lines changed: 2 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,13 @@
1818

1919
#import <UIKit/UIKit.h>
2020

21-
#import <GoogleUtilities/GULAppEnvironmentUtil.h>
22-
#import <GoogleUtilities/GULUserDefaults.h>
23-
2421
#import "FIRMessaging.h"
2522
#import "FIRMessagingLogger.h"
2623
#import "FIRMessagingUtilities.h"
2724
#import "FIRMessaging_Private.h"
2825

2926
static NSString *const kUpstreamMessageIDUserInfoKey = @"messageID";
3027
static NSString *const kUpstreamErrorUserInfoKey = @"error";
31-
/// "Should use Messaging delegate" key stored in NSUserDefaults
32-
NSString *const kFIRMessagingUserDefaultsKeyUseMessagingDelegate =
33-
@"com.firebase.messaging.useMessagingDelegate";
34-
/// "Should use Messaging Delegate" key stored in Info.plist
35-
NSString *const kFIRMessagingPlistUseMessagingDelegate =
36-
@"FirebaseMessagingUseMessagingDelegateForDirectChannel";
3728

3829
static int downstreamMessageID = 0;
3930

@@ -43,31 +34,14 @@ @interface FIRMessagingReceiver ()
4334

4435
@implementation FIRMessagingReceiver
4536

46-
#pragma mark - Initializer
47-
48-
- (instancetype)initWithUserDefaults:(GULUserDefaults *)defaults {
49-
self = [super init];
50-
if (self != nil) {
51-
_defaults = defaults;
52-
}
53-
return self;
54-
}
55-
5637
#pragma mark - FIRMessagingDataMessageManager protocol
5738

5839
- (void)didReceiveMessage:(NSDictionary *)message withIdentifier:(nullable NSString *)messageID {
5940
if (![messageID length]) {
6041
messageID = [[self class] nextMessageID];
6142
}
6243

63-
NSInteger majorOSVersion = [[GULAppEnvironmentUtil systemVersion] integerValue];
64-
if (majorOSVersion >= 10 || self.useDirectChannel) {
65-
// iOS 10 and above or use direct channel is enabled.
66-
[self scheduleIos10NotificationForMessage:message withIdentifier:messageID];
67-
} else {
68-
// Post notification directly to AppDelegate handlers. This is valid pre-iOS 10.
69-
[self scheduleNotificationForMessage:message];
70-
}
44+
[self handleDirectChannelMessage:message withIdentifier:messageID];
7145
}
7246

7347
- (void)willSendDataMessageWithID:(NSString *)messageID error:(NSError *)error {
@@ -112,83 +86,18 @@ - (void)didDeleteMessagesOnServer {
11286
}
11387

11488
#pragma mark - Private Helpers
115-
// As the new UserNotifications framework in iOS 10 doesn't support constructor/mutation for
116-
// UNNotification object, FCM can't inject the message to the app with UserNotifications framework.
117-
// Define our own protocol, which means app developers need to implement two interfaces to receive
118-
// display notifications and data messages respectively for devices running iOS 10 or above. Devices
119-
// running iOS 9 or below are not affected.
120-
- (void)scheduleIos10NotificationForMessage:(NSDictionary *)message
121-
withIdentifier:(NSString *)messageID {
89+
- (void)handleDirectChannelMessage:(NSDictionary *)message withIdentifier:(NSString *)messageID {
12290
FIRMessagingRemoteMessage *wrappedMessage = [[FIRMessagingRemoteMessage alloc] init];
123-
// TODO: wrap title, body, badge and other fields
12491
wrappedMessage.appData = [message copy];
12592
wrappedMessage.messageID = messageID;
12693
[self.delegate receiver:self receivedRemoteMessage:wrappedMessage];
12794
}
12895

129-
- (void)scheduleNotificationForMessage:(NSDictionary *)message {
130-
SEL newNotificationSelector =
131-
@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:);
132-
SEL oldNotificationSelector = @selector(application:didReceiveRemoteNotification:);
133-
134-
dispatch_async(dispatch_get_main_queue(), ^{
135-
UIApplication *application = FIRMessagingUIApplication();
136-
if (!application) {
137-
return;
138-
}
139-
id<UIApplicationDelegate> appDelegate = [application delegate];
140-
if ([appDelegate respondsToSelector:newNotificationSelector]) {
141-
// Try the new remote notification callback
142-
[appDelegate application:application
143-
didReceiveRemoteNotification:message
144-
fetchCompletionHandler:^(UIBackgroundFetchResult result) {
145-
}];
146-
147-
} else if ([appDelegate respondsToSelector:oldNotificationSelector]) {
148-
// Try the old remote notification callback
149-
#pragma clang diagnostic push
150-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
151-
[appDelegate application:application didReceiveRemoteNotification:message];
152-
#pragma clang diagnostic pop
153-
} else {
154-
FIRMessagingLoggerError(kFIRMessagingMessageCodeReceiver005,
155-
@"None of the remote notification callbacks implemented by "
156-
@"UIApplicationDelegate");
157-
}
158-
});
159-
}
160-
16196
+ (NSString *)nextMessageID {
16297
@synchronized (self) {
16398
++downstreamMessageID;
16499
return [NSString stringWithFormat:@"gcm-%d", downstreamMessageID];
165100
}
166101
}
167102

168-
- (BOOL)useDirectChannel {
169-
// Check storage
170-
id shouldUseMessagingDelegate =
171-
[_defaults objectForKey:kFIRMessagingUserDefaultsKeyUseMessagingDelegate];
172-
if (shouldUseMessagingDelegate) {
173-
return [shouldUseMessagingDelegate boolValue];
174-
}
175-
176-
// Check Info.plist
177-
shouldUseMessagingDelegate =
178-
[[NSBundle mainBundle] objectForInfoDictionaryKey:kFIRMessagingPlistUseMessagingDelegate];
179-
if (shouldUseMessagingDelegate) {
180-
return [shouldUseMessagingDelegate boolValue];
181-
}
182-
// If none of above exists, we go back to default behavior which is NO.
183-
return NO;
184-
}
185-
186-
- (void)setUseDirectChannel:(BOOL)useDirectChannel {
187-
BOOL shouldUseMessagingDelegate = [self useDirectChannel];
188-
if (useDirectChannel != shouldUseMessagingDelegate) {
189-
[_defaults setBool:useDirectChannel forKey:kFIRMessagingUserDefaultsKeyUseMessagingDelegate];
190-
[_defaults synchronize];
191-
}
192-
}
193-
194103
@end

Firebase/Messaging/Public/FIRMessaging.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,10 @@ NS_SWIFT_NAME(MessagingDelegate)
266266
didReceiveRegistrationToken:(NSString *)fcmToken
267267
NS_SWIFT_NAME(messaging(_:didReceiveRegistrationToken:));
268268

269-
/// This method is called on iOS 10+ devices to handle data messages received via FCM
270-
/// direct channel (not via APNS). For iOS 9 and below, the direct channel data message
271-
/// is handled by the UIApplicationDelegate's -application:didReceiveRemoteNotification: method.
272-
/// You can enable all direct channel data messages to be delivered in FIRMessagingDelegate
273-
/// by setting the flag `useMessagingDelegateForDirectMessages` to true.
269+
/// Handle data messages received via FCM direct channel (not via APNS).
274270
- (void)messaging:(FIRMessaging *)messaging
275271
didReceiveMessage:(FIRMessagingRemoteMessage *)remoteMessage
276-
NS_SWIFT_NAME(messaging(_:didReceive:))
277-
__IOS_AVAILABLE(10.0);
272+
NS_SWIFT_NAME(messaging(_:didReceive:));
278273

279274
@end
280275

@@ -309,23 +304,6 @@ NS_SWIFT_NAME(Messaging)
309304
*/
310305
@property(nonatomic, readonly) BOOL isDirectChannelEstablished;
311306

312-
/*
313-
* Whether direct channel message should only use FIRMessagingDelegate messaging(_:didReceive:)
314-
* for message delivery callback. The default value is false. If you need to change
315-
* the default, set FirebaseMessagingUseMessagingDelegateForDirectChannel to true in
316-
* your application’s Info.plist.
317-
*
318-
* If false, the message via direct channel for iOS 9 and below is still delivered in
319-
* `-UIApplicationDelegate application(_:didReceiveRemoteNotification:fetchCompletionHandler:)`,
320-
* and the FIRMessagingRemoteMessage object and its associated data will be unavailable.
321-
* For iOS 10 and above, it is still delivered in `FIRMessagingDelegate messaging(_:didReceive:)`.
322-
*
323-
* If true, the data message sent by direct channel will be delivered via
324-
* `FIRMessagingDelegate messaging(_:didReceive:)` and across all iOS versions.
325-
*/
326-
@property(nonatomic, assign) BOOL useMessagingDelegateForDirectChannel
327-
__deprecated_msg("This is soon to be deprecated. All direct messages will by default delivered in `FIRMessagingDelegate messaging(_:didReceive:)` across all iOS versions");
328-
329307
/**
330308
* FIRMessaging
331309
*

0 commit comments

Comments
 (0)