diff options
author | Chen Liang <chliang@google.com> | 2018-03-30 11:41:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-30 11:41:38 -0700 |
commit | 653aea7b50247bb0f6a7e8e1b4ab782553849f74 (patch) | |
tree | 0e2b9d8d660aee63a9a4659203e5ca9c1b692c61 /Firebase/Messaging/FIRMessagingTopicOperation.m | |
parent | cdd855423a79ed0191b37b7dcac2df9fb342c9a5 (diff) |
Adding a new topic subscription/unsubcription with completion handler method (#1001)
* add new topic subscription/unsubscription method with handler
Diffstat (limited to 'Firebase/Messaging/FIRMessagingTopicOperation.m')
-rw-r--r-- | Firebase/Messaging/FIRMessagingTopicOperation.m | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Firebase/Messaging/FIRMessagingTopicOperation.m b/Firebase/Messaging/FIRMessagingTopicOperation.m index 3120240..1546d47 100644 --- a/Firebase/Messaging/FIRMessagingTopicOperation.m +++ b/Firebase/Messaging/FIRMessagingTopicOperation.m @@ -125,7 +125,9 @@ NSString *FIRMessagingSubscriptionsServer() { - (void)start { if (self.isCancelled) { - [self finishWithResult:FIRMessagingTopicOperationResultCancelled error:nil]; + NSError *error = + [NSError errorWithFCMErrorCode:kFIRMessagingErrorCodePubSubOperationIsCancelled]; + [self finishWithError:error]; return; } @@ -134,14 +136,14 @@ NSString *FIRMessagingSubscriptionsServer() { [self performSubscriptionChange]; } -- (void)finishWithResult:(FIRMessagingTopicOperationResult)result error:(NSError *)error { +- (void)finishWithError:(NSError *)error { // Add a check to prevent this finish from being called more than once. if (self.isFinished) { return; } self.dataTask = nil; if (self.completion) { - self.completion(result, error); + self.completion(error); } [self setExecuting:NO]; @@ -151,7 +153,8 @@ NSString *FIRMessagingSubscriptionsServer() { - (void)cancel { [super cancel]; [self.dataTask cancel]; - [self finishWithResult:FIRMessagingTopicOperationResultCancelled error:nil]; + NSError *error = [NSError errorWithFCMErrorCode:kFIRMessagingErrorCodePubSubOperationIsCancelled]; + [self finishWithError:error]; } - (void)performSubscriptionChange { @@ -218,13 +221,12 @@ NSString *FIRMessagingSubscriptionsServer() { FIRMessagingLoggerDebug(kFIRMessagingMessageCodeTopicOption001, @"Device registration HTTP fetch error. Error Code: %ld", _FIRMessaging_L(error.code)); - [self finishWithResult:FIRMessagingTopicOperationResultError error:error]; + [self finishWithError:error]; return; } NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; if (response.length == 0) { - [self finishWithResult:FIRMessagingTopicOperationResultError - error:[NSError errorWithFCMErrorCode:kFIRMessagingErrorCodeUnknown]]; + [self finishWithError:[NSError errorWithFCMErrorCode:kFIRMessagingErrorCodeUnknown]]; return; } NSArray *parts = [response componentsSeparatedByString:@"="]; @@ -232,15 +234,14 @@ NSString *FIRMessagingSubscriptionsServer() { if (![parts[0] isEqualToString:@"token"] || parts.count <= 1) { FIRMessagingLoggerDebug(kFIRMessagingMessageCodeTopicOption002, @"Invalid registration request, response"); - [self finishWithResult:FIRMessagingTopicOperationResultError - error:[NSError errorWithFCMErrorCode:kFIRMessagingErrorCodeUnknown]]; + [self finishWithError:[NSError errorWithFCMErrorCode:kFIRMessagingErrorCodeUnknown]]; return; } #if DEBUG_LOG_SUBSCRIPTION_OPERATION_DURATIONS NSTimeInterval duration = -[start timeIntervalSinceNow]; FIRMessagingLoggerDebug(@"%@ change took %.2fs", self.topic, duration); #endif - [self finishWithResult:FIRMessagingTopicOperationResultSucceeded error:nil]; + [self finishWithError:nil]; }; |