FIRMessagingTokenOperation.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. @class FIRMessagingCheckinPreferences;
  18. @protocol FIRHeartbeatLoggerProtocol;
  19. NS_ASSUME_NONNULL_BEGIN
  20. /**
  21. * Represents the action taken on an FCM token.
  22. */
  23. typedef NS_ENUM(NSInteger, FIRMessagingTokenAction) {
  24. FIRMessagingTokenActionFetch,
  25. FIRMessagingTokenActionDeleteToken,
  26. FIRMessagingTokenActionDeleteTokenAndIID,
  27. };
  28. /**
  29. * Represents the possible results of a token operation.
  30. */
  31. typedef NS_ENUM(NSInteger, FIRMessagingTokenOperationResult) {
  32. FIRMessagingTokenOperationSucceeded,
  33. FIRMessagingTokenOperationError,
  34. FIRMessagingTokenOperationCancelled,
  35. };
  36. /**
  37. * Callback to invoke once the HTTP call to FIRMessaging backend for updating
  38. * subscription finishes.
  39. *
  40. * @param result The result of the operation.
  41. * @param token If the action for fetching a token and the request was successful, this will hold
  42. * the value of the token. Otherwise nil.
  43. * @param error The error which occurred while performing the token operation. This will be nil
  44. * in case the operation was successful, or if the operation was cancelled.
  45. */
  46. typedef void (^FIRMessagingTokenOperationCompletion)(FIRMessagingTokenOperationResult result,
  47. NSString *_Nullable token,
  48. NSError *_Nullable error);
  49. @interface FIRMessagingTokenOperation : NSOperation
  50. @property(nonatomic, readonly) FIRMessagingTokenAction action;
  51. @property(nonatomic, readonly, nullable) NSString *authorizedEntity;
  52. @property(nonatomic, readonly, nullable) NSString *scope;
  53. @property(nonatomic, readonly, nullable) NSDictionary<NSString *, NSString *> *options;
  54. @property(nonatomic, readonly, strong) FIRMessagingCheckinPreferences *checkinPreferences;
  55. @property(nonatomic, readonly, strong) NSString *instanceID;
  56. @property(nonatomic, readonly) FIRMessagingTokenOperationResult result;
  57. @property(atomic, strong, nullable) NSURLSessionDataTask *dataTask;
  58. @property(readonly) id<FIRHeartbeatLoggerProtocol> heartbeatLogger;
  59. #pragma mark - Request Construction
  60. + (NSMutableArray<NSURLQueryItem *> *)standardQueryItemsWithDeviceID:(NSString *)deviceID
  61. scope:(NSString *)scope;
  62. - (NSMutableURLRequest *)tokenRequest;
  63. - (instancetype)init NS_UNAVAILABLE;
  64. #pragma mark - Initialization
  65. - (instancetype)initWithAction:(FIRMessagingTokenAction)action
  66. forAuthorizedEntity:(nullable NSString *)authorizedEntity
  67. scope:(NSString *)scope
  68. options:(nullable NSDictionary<NSString *, NSString *> *)options
  69. checkinPreferences:(FIRMessagingCheckinPreferences *)checkinPreferences
  70. instanceID:(NSString *)instanceID
  71. heartbeatLogger:(id<FIRHeartbeatLoggerProtocol>)heartbeatLogger
  72. NS_DESIGNATED_INITIALIZER;
  73. - (void)addCompletionHandler:(FIRMessagingTokenOperationCompletion)handler;
  74. #pragma mark - Result
  75. - (void)finishWithResult:(FIRMessagingTokenOperationResult)result
  76. token:(nullable NSString *)token
  77. error:(nullable NSError *)error;
  78. @end
  79. NS_ASSUME_NONNULL_END