From 799a808de6ae2f2af4b4b331a841d7b001abacea Mon Sep 17 00:00:00 2001 From: Oleksiy Ivanov Date: Tue, 30 Jan 2018 16:33:12 -0800 Subject: [FCM] Add completion handler to subscribe/unsubscribe topic actions Added functionality not exposed in public header yet. I would leave to next FCM SDK owner to expose this functionality (and follow any required review process). Bugs: 72701086 --- Firebase/Messaging/FIRMessaging.m | 14 ++++++++++++-- Firebase/Messaging/FIRMessagingPubSub.h | 15 ++++++++++++--- Firebase/Messaging/FIRMessagingPubSub.m | 10 ++++++---- Firebase/Messaging/FIRMessagingTopicOperation.m | 1 + 4 files changed, 31 insertions(+), 9 deletions(-) (limited to 'Firebase/Messaging') 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/"`. + * @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/"`. + * @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/"`. + * @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/"`. + * @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; -- cgit v1.2.3