aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Oleksiy Ivanov <oleksiy@informationrd.com>2018-01-31 10:14:42 -0800
committerGravatar GitHub <noreply@github.com>2018-01-31 10:14:42 -0800
commit693d0649bfcc9c32201e2431ae08ea85fdbdb617 (patch)
tree63e39308f1e767a78e0619c5acec0813b3f8157f
parent3cbdbf2652202a3473271ed298ff50e5797cce68 (diff)
parent4e4c82b659b72e499c4c377400405327d233e556 (diff)
Merge pull request #732 from OleksiyA/FCM-subscribe-completion-1
[FCM] Add completion handler to subscribe/unsubscribe topic actions
-rw-r--r--Example/Messaging/Tests/FIRMessagingServiceTest.m11
-rw-r--r--Firebase/Messaging/FIRMessaging.m14
-rw-r--r--Firebase/Messaging/FIRMessagingPubSub.h15
-rw-r--r--Firebase/Messaging/FIRMessagingPubSub.m10
-rw-r--r--Firebase/Messaging/FIRMessagingTopicOperation.m1
5 files changed, 38 insertions, 13 deletions
diff --git a/Example/Messaging/Tests/FIRMessagingServiceTest.m b/Example/Messaging/Tests/FIRMessagingServiceTest.m
index c2b0853..c8d61c2 100644
--- a/Example/Messaging/Tests/FIRMessagingServiceTest.m
+++ b/Example/Messaging/Tests/FIRMessagingServiceTest.m
@@ -198,7 +198,8 @@
NSString *topicNameWithPrefix = [FIRMessagingPubSub addPrefixToTopic:topicName];
messaging.pubsub = mockPubSub;
messaging.defaultFcmToken = @"fake-default-token";
- OCMExpect([messaging.pubsub subscribeToTopic:[OCMArg isEqual:topicNameWithPrefix]]);
+ OCMExpect([messaging.pubsub subscribeToTopic:[OCMArg isEqual:topicNameWithPrefix]
+ handler:[OCMArg any]]);
[messaging subscribeToTopic:topicName];
OCMVerifyAll(mockPubSub);
// Need to swap back since it's a singleton and hence will live beyond the scope of this test.
@@ -213,7 +214,7 @@
NSString *topicName = @"/topics/topicWithoutPrefix";
messaging.pubsub = mockPubSub;
messaging.defaultFcmToken = @"fake-default-token";
- OCMExpect([messaging.pubsub subscribeToTopic:[OCMArg isEqual:topicName]]);
+ OCMExpect([messaging.pubsub subscribeToTopic:[OCMArg isEqual:topicName] handler:[OCMArg any]]);
[messaging subscribeToTopic:topicName];
OCMVerifyAll(mockPubSub);
// Need to swap back since it's a singleton and hence will live beyond the scope of this test.
@@ -229,7 +230,8 @@
NSString *topicNameWithPrefix = [FIRMessagingPubSub addPrefixToTopic:topicName];
messaging.pubsub = mockPubSub;
messaging.defaultFcmToken = @"fake-default-token";
- OCMExpect([messaging.pubsub unsubscribeFromTopic:[OCMArg isEqual:topicNameWithPrefix]]);
+ OCMExpect([messaging.pubsub unsubscribeFromTopic:[OCMArg isEqual:topicNameWithPrefix]
+ handler:[OCMArg any]]);
[messaging unsubscribeFromTopic:topicName];
OCMVerifyAll(mockPubSub);
// Need to swap back since it's a singleton and hence will live beyond the scope of this test.
@@ -244,7 +246,8 @@
NSString *topicName = @"/topics/topicWithPrefix";
messaging.pubsub = mockPubSub;
messaging.defaultFcmToken = @"fake-default-token";
- OCMExpect([messaging.pubsub unsubscribeFromTopic:[OCMArg isEqual:topicName]]);
+ OCMExpect([messaging.pubsub unsubscribeFromTopic:[OCMArg isEqual:topicName]
+ handler:[OCMArg any]]);
[messaging unsubscribeFromTopic:topicName];
OCMVerifyAll(mockPubSub);
// Need to swap back since it's a singleton and hence will live beyond the scope of this test.
diff --git a/Firebase/Messaging/FIRMessaging.m b/Firebase/Messaging/FIRMessaging.m
index 11cacb3..d0edadf 100644
--- a/Firebase/Messaging/FIRMessaging.m
+++ b/Firebase/Messaging/FIRMessaging.m
@@ -683,10 +683,15 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
}
- (void)subscribeToTopic:(NSString *)topic {
+ [self subscribeToTopic:topic completion:nil];
+}
+
+- (void)subscribeToTopic:(NSString *)topic
+ completion:(nullable FIRMessagingTopicOperationCompletion)completion {
if (self.defaultFcmToken.length && topic.length) {
NSString *normalizeTopic = [[self class ] normalizeTopic:topic];
if (normalizeTopic.length) {
- [self.pubsub subscribeToTopic:normalizeTopic];
+ [self.pubsub subscribeToTopic:normalizeTopic handler:completion];
} else {
FIRMessagingLoggerError(kFIRMessagingMessageCodeMessaging009,
@"Cannot parse topic name %@. Will not subscribe.", topic);
@@ -699,10 +704,15 @@ static NSString *const kFIRMessagingPlistAutoInitEnabled =
}
- (void)unsubscribeFromTopic:(NSString *)topic {
+ [self unsubscribeFromTopic:topic completion:nil];
+}
+
+- (void)unsubscribeFromTopic:(NSString *)topic
+ completion:(nullable FIRMessagingTopicOperationCompletion)completion {
if (self.defaultFcmToken.length && topic.length) {
NSString *normalizeTopic = [[self class] normalizeTopic:topic];
if (normalizeTopic.length) {
- [self.pubsub unsubscribeFromTopic:normalizeTopic];
+ [self.pubsub unsubscribeFromTopic:normalizeTopic handler:completion];
} else {
FIRMessagingLoggerError(kFIRMessagingMessageCodeMessaging011,
@"Cannot parse topic name %@. Will not unsubscribe.", topic);
diff --git a/Firebase/Messaging/FIRMessagingPubSub.h b/Firebase/Messaging/FIRMessagingPubSub.h
index 3a03494..2ce8ed4 100644
--- a/Firebase/Messaging/FIRMessagingPubSub.h
+++ b/Firebase/Messaging/FIRMessagingPubSub.h
@@ -59,6 +59,7 @@
* library for a given `authorizedEntity` and "gcm" scope.
* @param topic The topic to subscribe to. Should be of the form
* `"/topics/<topic-name>"`.
+ * @param options Unused parameter, please pass nil or empty dictionary.
* @param handler The callback handler invoked when the subscribe call
* ends. In case of success, a nil error is returned. Otherwise,
* an appropriate error object is returned.
@@ -70,7 +71,6 @@
options:(NSDictionary *)options
handler:(FIRMessagingTopicOperationCompletion)handler;
-
/**
* Unsubscribes an app instance from a topic, stopping it from receiving
* any further messages sent to that topic.
@@ -81,6 +81,7 @@
* @param token The token used to subscribe to this topic.
* @param topic The topic to unsubscribe from. Should be of the form
* `"/topics/<topic-name>"`.
+ * @param options Unused parameter, please pass nil or empty dictionary.
* @param handler The handler that is invoked once the unsubscribe call ends.
* In case of success, nil error is returned. Otherwise, an
* appropriate error object is returned.
@@ -98,8 +99,12 @@
* as compared to the `subscribe` method above which tries once.
*
* @param topic The topic name to subscribe to. Should be of the form `"/topics/<topic-name>"`.
+ * @param handler The handler that is invoked once the unsubscribe call ends.
+ * In case of success, nil error is returned. Otherwise, an
+ * appropriate error object is returned.
*/
-- (void)subscribeToTopic:(NSString *)topic;
+- (void)subscribeToTopic:(NSString *)topic
+ handler:(nullable FIRMessagingTopicOperationCompletion)handler;
/**
* Asynchronously unsubscribe from the topic. Adds to the pending list of topic operations.
@@ -107,8 +112,12 @@
* as compared to the `unsubscribe` method above which tries once.
*
* @param topic The topic name to unsubscribe from. Should be of the form `"/topics/<topic-name>"`.
+ * @param handler The handler that is invoked once the unsubscribe call ends.
+ * In case of success, nil error is returned. Otherwise, an
+ * appropriate error object is returned.
*/
-- (void)unsubscribeFromTopic:(NSString *)topic;
+- (void)unsubscribeFromTopic:(NSString *)topic
+ handler:(nullable FIRMessagingTopicOperationCompletion)handler;
/**
* Schedule subscriptions sync.
diff --git a/Firebase/Messaging/FIRMessagingPubSub.m b/Firebase/Messaging/FIRMessagingPubSub.m
index c8293e0..74a5292 100644
--- a/Firebase/Messaging/FIRMessagingPubSub.m
+++ b/Firebase/Messaging/FIRMessagingPubSub.m
@@ -146,16 +146,18 @@ static NSString *const kPendingSubscriptionsListKey =
}];
}
-- (void)subscribeToTopic:(NSString *)topic {
+- (void)subscribeToTopic:(NSString *)topic
+ handler:(nullable FIRMessagingTopicOperationCompletion)handler {
[self.pendingTopicUpdates addOperationForTopic:topic
withAction:FIRMessagingTopicActionSubscribe
- completion:nil];
+ completion:handler];
}
-- (void)unsubscribeFromTopic:(NSString *)topic {
+- (void)unsubscribeFromTopic:(NSString *)topic
+ handler:(nullable FIRMessagingTopicOperationCompletion)handler {
[self.pendingTopicUpdates addOperationForTopic:topic
withAction:FIRMessagingTopicActionUnsubscribe
- completion:nil];
+ completion:handler];
}
- (void)scheduleSync:(BOOL)immediately {
diff --git a/Firebase/Messaging/FIRMessagingTopicOperation.m b/Firebase/Messaging/FIRMessagingTopicOperation.m
index 90760eb..3120240 100644
--- a/Firebase/Messaging/FIRMessagingTopicOperation.m
+++ b/Firebase/Messaging/FIRMessagingTopicOperation.m
@@ -82,6 +82,7 @@ NSString *FIRMessagingSubscriptionsServer() {
_topic = topic;
_action = action;
_token = token;
+ _options = options;
_checkinService = checkinService;
_completion = completion;