From 468cb9151791a313d44e382976e6aa22fec45db4 Mon Sep 17 00:00:00 2001 From: Chen Liang Date: Tue, 19 Jun 2018 15:59:04 -0700 Subject: add a warning message that the topic operation is suspended without a token (#1427) --- Firebase/Messaging/FIRMessaging.m | 73 ++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'Firebase') diff --git a/Firebase/Messaging/FIRMessaging.m b/Firebase/Messaging/FIRMessaging.m index efafcc2..100c18a 100644 --- a/Firebase/Messaging/FIRMessaging.m +++ b/Firebase/Messaging/FIRMessaging.m @@ -680,6 +680,9 @@ NSString *const kFIRMessagingPlistAutoInitEnabled = #pragma mark - Topics + (NSString *)normalizeTopic:(NSString *)topic { + if (!topic.length) { + return nil; + } if (![FIRMessagingPubSub hasTopicsPrefix:topic]) { topic = [FIRMessagingPubSub addPrefixToTopic:topic]; } @@ -695,25 +698,24 @@ NSString *const kFIRMessagingPlistAutoInitEnabled = - (void)subscribeToTopic:(NSString *)topic completion:(nullable FIRMessagingTopicOperationCompletion)completion { - if (topic.length) { - NSString *normalizeTopic = [[self class ] normalizeTopic:topic]; - if ([FIRMessagingPubSub hasTopicsPrefix:topic]) { - FIRMessagingLoggerWarn(kFIRMessagingMessageCodeTopicFormatIsDeprecated, - @"Format '%@' is deprecated. Only '%@' should be used in " - @"subscribeToTopic.", topic, - [FIRMessagingPubSub removePrefixFromTopic:topic]); - } - if (normalizeTopic.length) { - [self.pubsub subscribeToTopic:normalizeTopic handler:completion]; - } else { - FIRMessagingLoggerError(kFIRMessagingMessageCodeMessaging009, - @"Cannot parse topic name %@. Will not subscribe.", topic); - } - } else { - FIRMessagingLoggerError(kFIRMessagingMessageCodeMessaging010, - @"Cannot subscribe to topic: %@ with token: %@", topic, - self.defaultFcmToken); + if ([FIRMessagingPubSub hasTopicsPrefix:topic]) { + FIRMessagingLoggerWarn(kFIRMessagingMessageCodeTopicFormatIsDeprecated, + @"Format '%@' is deprecated. Only '%@' should be used in " + @"subscribeToTopic.", + topic, [FIRMessagingPubSub removePrefixFromTopic:topic]); + } + if (!self.defaultFcmToken.length) { + FIRMessagingLoggerWarn(kFIRMessagingMessageCodeMessaging010, + @"The subscription operation is suspended because you don't have a " + @"token. The operation will resume once you get an FCM token."); + } + NSString *normalizeTopic = [[self class] normalizeTopic:topic]; + if (normalizeTopic.length) { + [self.pubsub subscribeToTopic:normalizeTopic handler:completion]; + return; } + FIRMessagingLoggerError(kFIRMessagingMessageCodeMessaging009, + @"Cannot parse topic name %@. Will not subscribe.", topic); } - (void)unsubscribeFromTopic:(NSString *)topic { @@ -722,25 +724,24 @@ NSString *const kFIRMessagingPlistAutoInitEnabled = - (void)unsubscribeFromTopic:(NSString *)topic completion:(nullable FIRMessagingTopicOperationCompletion)completion { - if (topic.length) { - NSString *normalizeTopic = [[self class] normalizeTopic:topic]; - if ([FIRMessagingPubSub hasTopicsPrefix:topic]) { - FIRMessagingLoggerWarn(kFIRMessagingMessageCodeTopicFormatIsDeprecated, - @"Format '%@' is deprecated. Only '%@' should be used in " - @"unsubscribeFromTopic.", topic, - [FIRMessagingPubSub removePrefixFromTopic:topic]); - } - if (normalizeTopic.length) { - [self.pubsub unsubscribeFromTopic:normalizeTopic handler:completion]; - } else { - FIRMessagingLoggerError(kFIRMessagingMessageCodeMessaging011, - @"Cannot parse topic name %@. Will not unsubscribe.", topic); - } - } else { - FIRMessagingLoggerError(kFIRMessagingMessageCodeMessaging012, - @"Cannot unsubscribe to topic: %@ with token: %@", topic, - self.defaultFcmToken); + if ([FIRMessagingPubSub hasTopicsPrefix:topic]) { + FIRMessagingLoggerWarn(kFIRMessagingMessageCodeTopicFormatIsDeprecated, + @"Format '%@' is deprecated. Only '%@' should be used in " + @"unsubscribeFromTopic.", + topic, [FIRMessagingPubSub removePrefixFromTopic:topic]); + } + if (!self.defaultFcmToken.length) { + FIRMessagingLoggerWarn(kFIRMessagingMessageCodeMessaging012, + @"The unsubscription operation is suspended because you don't have a " + @"token. The operation will resume once you get an FCM token."); + } + NSString *normalizeTopic = [[self class] normalizeTopic:topic]; + if (normalizeTopic.length) { + [self.pubsub unsubscribeFromTopic:normalizeTopic handler:completion]; + return; } + FIRMessagingLoggerError(kFIRMessagingMessageCodeMessaging011, + @"Cannot parse topic name %@. Will not unsubscribe.", topic); } #pragma mark - Send -- cgit v1.2.3