Skip to content

Commit 6a1ddb9

Browse files
committed
Merge branch 'master' into bs-core-tests
* master: (36 commits) Make sure Firestore/core/include is in the podspec (#748) fix null block execution crash Increase expectation timeout to 25 seconds. (#744) fix (#739) Align tests and integration test header search paths (#737) Remove predecessorKey,Object,Document, etc (#735) Start on ArraySortedMap in C++ (#721) Move all Firestore Objective-C to Objective-C++ (#734) Fix tests. [FCM] Add completion handler to subscribe/unsubscribe topic actions Schema migrations for LevelDB (#728) Firestore DatabaseId in C++ (#727) Add absl_strings to firebase_firestore_util_test dependencies (#725) Add changelog entry for my last PR (oops) and also add a few that we missed last release. (#724) Import iterator_adaptors from google3 (#718) Use fixed-sized types (#719) Version updates to 4.8.2 (#722) Fix a number of c++ build errors (#715) Add the C++ linter to the repo (#720) travis: check for copyright in sources (#717) ...
2 parents c6c3936 + 32266c5 commit 6a1ddb9

File tree

240 files changed

+12444
-1464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+12444
-1464
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ before_install:
2828
2929
script:
3030
- "! git grep -I ' $'" # Fail on trailing whitespace in non-binary files
31+
- "! git grep -EL --name-only 'Copyright [0-9]{4}.*Google' | grep -v third_party | egrep '\\.(m|h|cc|mm|c)$'"
3132
- ./scripts/style.sh test-only # Validate clang-format compliance
3233
- |
3334
if [ $SKIP_FIREBASE != 1 ]; then

Example/Messaging/App/iOS/Messaging-Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>FirebaseMessagingAutoInitEnabled</key>
6+
<false/>
57
<key>CFBundleDevelopmentRegion</key>
68
<string>en</string>
79
<key>CFBundleDisplayName</key>

Example/Messaging/Tests/FIRMessagingServiceTest.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ - (void)testSubscribeWithNoTopicPrefix {
198198
NSString *topicNameWithPrefix = [FIRMessagingPubSub addPrefixToTopic:topicName];
199199
messaging.pubsub = mockPubSub;
200200
messaging.defaultFcmToken = @"fake-default-token";
201-
OCMExpect([messaging.pubsub subscribeToTopic:[OCMArg isEqual:topicNameWithPrefix]]);
201+
OCMExpect([messaging.pubsub subscribeToTopic:[OCMArg isEqual:topicNameWithPrefix]
202+
handler:[OCMArg any]]);
202203
[messaging subscribeToTopic:topicName];
203204
OCMVerifyAll(mockPubSub);
204205
// Need to swap back since it's a singleton and hence will live beyond the scope of this test.
@@ -213,7 +214,7 @@ - (void)testSubscribeWithTopicPrefix {
213214
NSString *topicName = @"/topics/topicWithoutPrefix";
214215
messaging.pubsub = mockPubSub;
215216
messaging.defaultFcmToken = @"fake-default-token";
216-
OCMExpect([messaging.pubsub subscribeToTopic:[OCMArg isEqual:topicName]]);
217+
OCMExpect([messaging.pubsub subscribeToTopic:[OCMArg isEqual:topicName] handler:[OCMArg any]]);
217218
[messaging subscribeToTopic:topicName];
218219
OCMVerifyAll(mockPubSub);
219220
// Need to swap back since it's a singleton and hence will live beyond the scope of this test.
@@ -229,7 +230,8 @@ - (void)testUnsubscribeWithNoTopicPrefix {
229230
NSString *topicNameWithPrefix = [FIRMessagingPubSub addPrefixToTopic:topicName];
230231
messaging.pubsub = mockPubSub;
231232
messaging.defaultFcmToken = @"fake-default-token";
232-
OCMExpect([messaging.pubsub unsubscribeFromTopic:[OCMArg isEqual:topicNameWithPrefix]]);
233+
OCMExpect([messaging.pubsub unsubscribeFromTopic:[OCMArg isEqual:topicNameWithPrefix]
234+
handler:[OCMArg any]]);
233235
[messaging unsubscribeFromTopic:topicName];
234236
OCMVerifyAll(mockPubSub);
235237
// Need to swap back since it's a singleton and hence will live beyond the scope of this test.
@@ -244,7 +246,8 @@ - (void)testUnsubscribeWithTopicPrefix {
244246
NSString *topicName = @"/topics/topicWithPrefix";
245247
messaging.pubsub = mockPubSub;
246248
messaging.defaultFcmToken = @"fake-default-token";
247-
OCMExpect([messaging.pubsub unsubscribeFromTopic:[OCMArg isEqual:topicName]]);
249+
OCMExpect([messaging.pubsub unsubscribeFromTopic:[OCMArg isEqual:topicName]
250+
handler:[OCMArg any]]);
248251
[messaging unsubscribeFromTopic:topicName];
249252
OCMVerifyAll(mockPubSub);
250253
// Need to swap back since it's a singleton and hence will live beyond the scope of this test.

Example/Messaging/Tests/FIRMessagingTest.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#import "FIRMessaging.h"
2222
#import "FIRMessagingInstanceIDProxy.h"
23+
#import "FIRMessaging_Private.h"
2324

2425
extern NSString *const kFIRMessagingFCMTokenFetchAPNSOption;
2526

@@ -28,6 +29,7 @@ @interface FIRMessaging ()
2829
@property(nonatomic, readwrite, strong) NSString *defaultFcmToken;
2930
@property(nonatomic, readwrite, strong) NSData *apnsTokenData;
3031
@property(nonatomic, readwrite, strong) FIRMessagingInstanceIDProxy *instanceIDProxy;
32+
@property(nonatomic, readwrite, strong) NSUserDefaults *messagingUserDefaults;
3133

3234
- (instancetype)initPrivately;
3335
// Direct Channel Methods
@@ -52,6 +54,9 @@ - (void)setUp {
5254
_mockMessaging = OCMPartialMock(self.messaging);
5355
_mockInstanceIDProxy = OCMPartialMock(self.messaging.instanceIDProxy);
5456
self.messaging.instanceIDProxy = _mockInstanceIDProxy;
57+
[self.messaging.messagingUserDefaults removePersistentDomainForName:kFIRMessagingSuiteName];
58+
self.messaging.messagingUserDefaults =
59+
[[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingSuiteName];
5560
}
5661

5762
- (void)tearDown {
@@ -60,6 +65,15 @@ - (void)tearDown {
6065
[super tearDown];
6166
}
6267

68+
- (void)testAutoInitEnableFlag {
69+
// Should read from Info.plist
70+
XCTAssertFalse(_messaging.isAutoInitEnabled);
71+
72+
// Now set the flag should overwrite Info.plist value.
73+
_messaging.autoInitEnabled = YES;
74+
XCTAssertTrue(_messaging.isAutoInitEnabled);
75+
}
76+
6377
#pragma mark - Direct Channel Establishment Testing
6478

6579
// Should connect with valid token and application in foreground

Example/Messaging/Tests/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
2222
<string>1</string>
23+
<key>FirebaseMessagingAutoInitEnabled</key>
24+
<false/>
2325
</dict>
2426
</plist>

Example/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ target 'Core_Example_iOS' do
88
# The next line is the forcing function for the Firebase pod. The Firebase
99
# version's subspecs should depend on the component versions in their
1010
# corresponding podspec's.
11-
pod 'Firebase/Core', '4.8.1'
11+
pod 'Firebase/Core', '4.8.2'
1212

1313
target 'Core_Tests_iOS' do
1414
inherit! :search_paths

Firebase/Auth/FirebaseAuth.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Simplify your iOS development, grow your user base, and monetize more effectivel
4545
'$(inherited) ' + 'FIRAuth_VERSION=' + s.version.to_s +
4646
' FIRAuth_MINOR_VERSION=' + s.version.to_s.split(".")[0] + "." + s.version.to_s.split(".")[1]
4747
}
48+
s.framework = 'CoreGraphics'
4849
s.framework = 'SafariServices'
4950
s.framework = 'Security'
5051
# s.dependency 'FirebaseCommunity/Core'

Firebase/Auth/Source/Public/FIREmailAuthProvider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
2626
extern NSString *const FIREmailAuthProviderID NS_SWIFT_NAME(EmailAuthProviderID);
2727

2828
/**
29-
@brief please use `FIREmailAuthProviderID` instead.
29+
@brief Please use `FIREmailAuthProviderID` for Objective-C or `EmailAuthProviderID` for Swift instead.
3030
*/
3131
extern NSString *const FIREmailPasswordAuthProviderID __attribute__((deprecated));
3232

Firebase/Core/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# v4.0.14 -- M21.1
1+
# Unreleased
2+
3+
# 2018-01-18 -- v4.0.14 -- M21.1
24
- [changed] Removed AppKit dependency for community macOS build.
35

46
# 2017-11-30 -- v4.0.12 -- M20.2

Firebase/Messaging/FIRMessaging.m

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@
7070
@"com.firebase.messaging.notif.fcm-token-refreshed";
7171
#endif // defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
7272

73+
NSString *const kFIRMessagingUserDefaultsKeyAutoInitEnabled =
74+
@"com.firebase.messaging.auto-init.enabled"; // Auto Init Enabled key stored in NSUserDefaults
75+
NSString *const kFIRMessagingSuiteName =
76+
@"com.firebase.messaging.user_defaults"; // Suite name for NSUserDefaults
77+
78+
static NSString *const kFIRMessagingPlistAutoInitEnabled =
79+
@"FirebaseMessagingAutoInitEnabled"; // Auto Init Enabled key stored in Info.plist
80+
7381
// Copied from Apple's header in case it is missing in some cases (e.g. pre-Xcode 8 builds).
7482
#ifndef NSFoundationVersionNumber_iOS_8_x_Max
7583
#define NSFoundationVersionNumber_iOS_8_x_Max 1199
@@ -120,8 +128,8 @@ - (instancetype)initWithMessage:(FIRMessagingRemoteMessage *)message {
120128

121129
@end
122130

123-
@interface FIRMessaging ()
124-
<FIRMessagingClientDelegate, FIRMessagingReceiverDelegate, FIRReachabilityDelegate>
131+
@interface FIRMessaging ()<FIRMessagingClientDelegate, FIRMessagingReceiverDelegate,
132+
FIRReachabilityDelegate>
125133

126134
// FIRApp properties
127135
@property(nonatomic, readwrite, copy) NSString *fcmSenderID;
@@ -141,6 +149,7 @@ @interface FIRMessaging ()
141149
@property(nonatomic, readwrite, strong) FIRMessagingRmqManager *rmq2Manager;
142150
@property(nonatomic, readwrite, strong) FIRMessagingReceiver *receiver;
143151
@property(nonatomic, readwrite, strong) FIRMessagingSyncMessageManager *syncMessageManager;
152+
@property(nonatomic, readwrite, strong) NSUserDefaults *messagingUserDefaults;
144153

145154
/// Message ID's logged for analytics. This prevents us from logging the same message twice
146155
/// which can happen if the user inadvertently calls `appDidReceiveMessage` along with us
@@ -166,6 +175,7 @@ - (instancetype)initPrivately {
166175
if (self) {
167176
_loggedMessageIDs = [NSMutableSet set];
168177
_instanceIDProxy = [[FIRMessagingInstanceIDProxy alloc] init];
178+
_messagingUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:kFIRMessagingSuiteName];
169179
}
170180
return self;
171181
}
@@ -451,6 +461,33 @@ - (void)setAPNSToken:(NSData *)apnsToken type:(FIRMessagingAPNSTokenType)type {
451461

452462
#pragma mark - FCM
453463

464+
- (BOOL)isAutoInitEnabled {
465+
// Check storage
466+
id isAutoInitEnabledObject =
467+
[_messagingUserDefaults objectForKey:kFIRMessagingUserDefaultsKeyAutoInitEnabled];
468+
if (isAutoInitEnabledObject) {
469+
return [isAutoInitEnabledObject boolValue];
470+
}
471+
472+
// Check Info.plist
473+
isAutoInitEnabledObject =
474+
[[NSBundle mainBundle] objectForInfoDictionaryKey:kFIRMessagingPlistAutoInitEnabled];
475+
if (isAutoInitEnabledObject) {
476+
return [isAutoInitEnabledObject boolValue];
477+
}
478+
// If none of above exists, we default assume FCM auto init is enabled.
479+
return YES;
480+
}
481+
482+
- (void)setAutoInitEnabled:(BOOL)autoInitEnabled {
483+
BOOL isFCMAutoInitEnabled = [self isAutoInitEnabled];
484+
[_messagingUserDefaults setBool:autoInitEnabled
485+
forKey:kFIRMessagingUserDefaultsKeyAutoInitEnabled];
486+
if (!isFCMAutoInitEnabled && autoInitEnabled) {
487+
self.defaultFcmToken = [self.instanceIDProxy token];
488+
}
489+
}
490+
454491
- (NSString *)FCMToken {
455492
NSString *token = self.defaultFcmToken;
456493
if (!token) {
@@ -646,10 +683,15 @@ + (NSString *)normalizeTopic:(NSString *)topic {
646683
}
647684

648685
- (void)subscribeToTopic:(NSString *)topic {
686+
[self subscribeToTopic:topic completion:nil];
687+
}
688+
689+
- (void)subscribeToTopic:(NSString *)topic
690+
completion:(nullable FIRMessagingTopicOperationCompletion)completion {
649691
if (self.defaultFcmToken.length && topic.length) {
650692
NSString *normalizeTopic = [[self class ] normalizeTopic:topic];
651693
if (normalizeTopic.length) {
652-
[self.pubsub subscribeToTopic:normalizeTopic];
694+
[self.pubsub subscribeToTopic:normalizeTopic handler:completion];
653695
} else {
654696
FIRMessagingLoggerError(kFIRMessagingMessageCodeMessaging009,
655697
@"Cannot parse topic name %@. Will not subscribe.", topic);
@@ -662,10 +704,15 @@ - (void)subscribeToTopic:(NSString *)topic {
662704
}
663705

664706
- (void)unsubscribeFromTopic:(NSString *)topic {
707+
[self unsubscribeFromTopic:topic completion:nil];
708+
}
709+
710+
- (void)unsubscribeFromTopic:(NSString *)topic
711+
completion:(nullable FIRMessagingTopicOperationCompletion)completion {
665712
if (self.defaultFcmToken.length && topic.length) {
666713
NSString *normalizeTopic = [[self class] normalizeTopic:topic];
667714
if (normalizeTopic.length) {
668-
[self.pubsub unsubscribeFromTopic:normalizeTopic];
715+
[self.pubsub unsubscribeFromTopic:normalizeTopic handler:completion];
669716
} else {
670717
FIRMessagingLoggerError(kFIRMessagingMessageCodeMessaging011,
671718
@"Cannot parse topic name %@. Will not unsubscribe.", topic);
@@ -787,7 +834,7 @@ - (FIRMessagingNetworkStatus)networkType {
787834
#pragma mark - Notifications
788835

789836
- (void)didReceiveDefaultInstanceIDToken:(NSNotification *)notification {
790-
if (![notification.object isKindOfClass:[NSString class]]) {
837+
if (notification.object && ![notification.object isKindOfClass:[NSString class]]) {
791838
FIRMessagingLoggerDebug(kFIRMessagingMessageCodeMessaging015,
792839
@"Invalid default FCM token type %@",
793840
NSStringFromClass([notification.object class]));

Firebase/Messaging/FIRMessagingPubSub.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
* library for a given `authorizedEntity` and "gcm" scope.
6060
* @param topic The topic to subscribe to. Should be of the form
6161
* `"/topics/<topic-name>"`.
62+
* @param options Unused parameter, please pass nil or empty dictionary.
6263
* @param handler The callback handler invoked when the subscribe call
6364
* ends. In case of success, a nil error is returned. Otherwise,
6465
* an appropriate error object is returned.
@@ -70,7 +71,6 @@
7071
options:(NSDictionary *)options
7172
handler:(FIRMessagingTopicOperationCompletion)handler;
7273

73-
7474
/**
7575
* Unsubscribes an app instance from a topic, stopping it from receiving
7676
* any further messages sent to that topic.
@@ -81,6 +81,7 @@
8181
* @param token The token used to subscribe to this topic.
8282
* @param topic The topic to unsubscribe from. Should be of the form
8383
* `"/topics/<topic-name>"`.
84+
* @param options Unused parameter, please pass nil or empty dictionary.
8485
* @param handler The handler that is invoked once the unsubscribe call ends.
8586
* In case of success, nil error is returned. Otherwise, an
8687
* appropriate error object is returned.
@@ -98,17 +99,25 @@
9899
* as compared to the `subscribe` method above which tries once.
99100
*
100101
* @param topic The topic name to subscribe to. Should be of the form `"/topics/<topic-name>"`.
102+
* @param handler The handler that is invoked once the unsubscribe call ends.
103+
* In case of success, nil error is returned. Otherwise, an
104+
* appropriate error object is returned.
101105
*/
102-
- (void)subscribeToTopic:(NSString *)topic;
106+
- (void)subscribeToTopic:(NSString *)topic
107+
handler:(nullable FIRMessagingTopicOperationCompletion)handler;
103108

104109
/**
105110
* Asynchronously unsubscribe from the topic. Adds to the pending list of topic operations.
106111
* Retry in case of failures. This makes a repeated attempt to unsubscribe from the topic
107112
* as compared to the `unsubscribe` method above which tries once.
108113
*
109114
* @param topic The topic name to unsubscribe from. Should be of the form `"/topics/<topic-name>"`.
115+
* @param handler The handler that is invoked once the unsubscribe call ends.
116+
* In case of success, nil error is returned. Otherwise, an
117+
* appropriate error object is returned.
110118
*/
111-
- (void)unsubscribeFromTopic:(NSString *)topic;
119+
- (void)unsubscribeFromTopic:(NSString *)topic
120+
handler:(nullable FIRMessagingTopicOperationCompletion)handler;
112121

113122
/**
114123
* Schedule subscriptions sync.

Firebase/Messaging/FIRMessagingPubSub.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,18 @@ - (void)unsubscribeWithToken:(NSString *)token
146146
}];
147147
}
148148

149-
- (void)subscribeToTopic:(NSString *)topic {
149+
- (void)subscribeToTopic:(NSString *)topic
150+
handler:(nullable FIRMessagingTopicOperationCompletion)handler {
150151
[self.pendingTopicUpdates addOperationForTopic:topic
151152
withAction:FIRMessagingTopicActionSubscribe
152-
completion:nil];
153+
completion:handler];
153154
}
154155

155-
- (void)unsubscribeFromTopic:(NSString *)topic {
156+
- (void)unsubscribeFromTopic:(NSString *)topic
157+
handler:(nullable FIRMessagingTopicOperationCompletion)handler {
156158
[self.pendingTopicUpdates addOperationForTopic:topic
157159
withAction:FIRMessagingTopicActionUnsubscribe
158-
completion:nil];
160+
completion:handler];
159161
}
160162

161163
- (void)scheduleSync:(BOOL)immediately {

Firebase/Messaging/FIRMessagingTopicOperation.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ - (instancetype)initWithTopic:(NSString *)topic
8282
_topic = topic;
8383
_action = action;
8484
_token = token;
85+
_options = options;
8586
_checkinService = checkinService;
8687
_completion = completion;
8788

Firebase/Messaging/FIRMessaging_Private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ typedef NS_ENUM(int8_t, FIRMessagingNetworkStatus) {
2525
kFIRMessagingReachabilityReachableViaWWAN,
2626
};
2727

28+
FOUNDATION_EXPORT NSString *const kFIRMessagingUserDefaultsKeyAutoInitEnabled;
29+
FOUNDATION_EXPORT NSString *const kFIRMessagingSuiteName;
30+
2831
@interface FIRMessagingRemoteMessage ()
2932

3033
@property(nonatomic, strong) NSDictionary *appData;

Firebase/Messaging/Public/FIRMessaging.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ NS_SWIFT_NAME(Messaging)
289289
*/
290290
@property(nonatomic, weak, nullable) id<FIRMessagingDelegate> delegate;
291291

292-
293292
/**
294293
* Delegate to handle remote data messages received via FCM for devices running iOS 10 or above.
295294
*/
@@ -353,6 +352,20 @@ NS_SWIFT_NAME(Messaging)
353352

354353
#pragma mark - FCM Tokens
355354

355+
/**
356+
* Is Firebase Messaging token auto generation enabled? If this flag is disabled,
357+
* Firebase Messaging will not generate token automatically for message delivery.
358+
*
359+
* This setting is persisted, and is applied on future
360+
* invocations of your application. Once explicitly set, it overrides any
361+
* settings in your Info.plist.
362+
*
363+
* By default, FCM automatic initialization is enabled. If you need to change the
364+
* default (for example, because you want to prompt the user before getting token)
365+
* set FirebaseMessagingAutoInitEnabled to false in your application's Info.plist.
366+
*/
367+
@property(nonatomic, assign, getter=isAutoInitEnabled) BOOL autoInitEnabled;
368+
356369
/**
357370
* The FCM token is used to identify this device so that FCM can send notifications to it.
358371
* It is associated with your APNS token when the APNS token is supplied, so that sending

0 commit comments

Comments
 (0)