FIRMessagingTokenOperation.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. NS_ASSUME_NONNULL_BEGIN
  19. /**
  20. * Represents the action taken on an FCM token.
  21. */
  22. typedef NS_ENUM(NSInteger, FIRMessagingTokenAction) {
  23. FIRMessagingTokenActionFetch,
  24. FIRMessagingTokenActionDeleteToken,
  25. FIRMessagingTokenActionDeleteTokenAndIID,
  26. };
  27. /**
  28. * Represents the possible results of a token operation.
  29. */
  30. typedef NS_ENUM(NSInteger, FIRMessagingTokenOperationResult) {
  31. FIRMessagingTokenOperationSucceeded,
  32. FIRMessagingTokenOperationError,
  33. FIRMessagingTokenOperationCancelled,
  34. };
  35. /**
  36. * Callback to invoke once the HTTP call to FIRMessaging backend for updating
  37. * subscription finishes.
  38. *
  39. * @param result The result of the operation.
  40. * @param token If the action for fetching a token and the request was successful, this will hold
  41. * the value of the token. Otherwise nil.
  42. * @param error The error which occurred while performing the token operation. This will be nil
  43. * in case the operation was successful, or if the operation was cancelled.
  44. */
  45. typedef void (^FIRMessagingTokenOperationCompletion)(FIRMessagingTokenOperationResult result,
  46. NSString *_Nullable token,
  47. NSError *_Nullable error);
  48. @interface FIRMessagingTokenOperation : NSOperation
  49. @property(nonatomic, readonly) FIRMessagingTokenAction action;
  50. @property(nonatomic, readonly, nullable) NSString *authorizedEntity;
  51. @property(nonatomic, readonly, nullable) NSString *scope;
  52. @property(nonatomic, readonly, nullable) NSDictionary<NSString *, NSString *> *options;
  53. @property(nonatomic, readonly, strong) FIRMessagingCheckinPreferences *checkinPreferences;
  54. @property(nonatomic, readonly, strong) NSString *instanceID;
  55. @property(nonatomic, readonly) FIRMessagingTokenOperationResult result;
  56. @property(atomic, strong, nullable) NSURLSessionDataTask *dataTask;
  57. #pragma mark - Request Construction
  58. + (NSMutableArray<NSURLQueryItem *> *)standardQueryItemsWithDeviceID:(NSString *)deviceID
  59. scope:(NSString *)scope;
  60. - (NSMutableURLRequest *)tokenRequest;
  61. - (instancetype)init NS_UNAVAILABLE;
  62. #pragma mark - Initialization
  63. - (instancetype)initWithAction:(FIRMessagingTokenAction)action
  64. forAuthorizedEntity:(nullable NSString *)authorizedEntity
  65. scope:(NSString *)scope
  66. options:(nullable NSDictionary<NSString *, NSString *> *)options
  67. checkinPreferences:(FIRMessagingCheckinPreferences *)checkinPreferences
  68. instanceID:(NSString *)instanceID;
  69. - (void)addCompletionHandler:(FIRMessagingTokenOperationCompletion)handler;
  70. #pragma mark - Result
  71. - (void)finishWithResult:(FIRMessagingTokenOperationResult)result
  72. token:(nullable NSString *)token
  73. error:(nullable NSError *)error;
  74. @end
  75. NS_ASSUME_NONNULL_END