Нет описания

FIRInstanceIDStore.h 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. NS_ASSUME_NONNULL_BEGIN
  18. @class FIRInstanceIDBackupExcludedPlist;
  19. @class FIRInstanceIDCheckinPreferences;
  20. @class FIRInstanceIDCheckinStore;
  21. @class FIRInstanceIDTokenInfo;
  22. @class FIRInstanceIDTokenStore;
  23. @class FIRInstanceIDStore;
  24. @protocol FIRInstanceIDStoreDelegate <NSObject>
  25. /**
  26. * This is called when the store has decided to invalide its tokens associated with the
  27. * previous checkin credentials. After deleting the tokens locally, it calls this method
  28. * to notify the delegate of the change. If possible, the delegate should use this time
  29. * to request the invalidation of the tokens on the server as well.
  30. */
  31. - (void)store:(FIRInstanceIDStore *)store
  32. didDeleteFCMScopedTokensForCheckin:(FIRInstanceIDCheckinPreferences *)checkin;
  33. @end
  34. /**
  35. * Used to persist the InstanceID tokens. This is also used to cache the Checkin
  36. * credentials. The store also checks for stale entries in the store and
  37. * let's us know if things in the store are stale or not. It does not however
  38. * acts on stale entries in anyway.
  39. */
  40. @interface FIRInstanceIDStore : NSObject
  41. /**
  42. * The delegate set in the initializer which is notified of changes in the store.
  43. */
  44. @property(nonatomic, readonly, weak) NSObject<FIRInstanceIDStoreDelegate> *delegate;
  45. - (instancetype)init __attribute__((unavailable("Use initWithDelegate: instead.")));
  46. /**
  47. * Initialize a default store to persist InstanceID tokens and options.
  48. *
  49. * @param delegate The delegate with which to be notified of changes in the store.
  50. * @return Store to persist InstanceID tokens.
  51. */
  52. - (instancetype)initWithDelegate:(NSObject<FIRInstanceIDStoreDelegate> *)delegate;
  53. /**
  54. * Initialize a store with the token store used to persist tokens, and a checkin store.
  55. * Used for testing.
  56. *
  57. * @param checkinStore Persistent store that persists checkin preferences.
  58. * @param tokenStore Persistent store that persists tokens.
  59. *
  60. * @return Store to persist InstanceID tokens and options.
  61. */
  62. - (instancetype)initWithCheckinStore:(FIRInstanceIDCheckinStore *)checkinStore
  63. tokenStore:(FIRInstanceIDTokenStore *)tokenStore
  64. delegate:(NSObject<FIRInstanceIDStoreDelegate> *)delegate
  65. NS_DESIGNATED_INITIALIZER;
  66. #pragma mark - Save
  67. /**
  68. * Save the instanceID token info to the store.
  69. *
  70. * @param tokenInfo The token info to store.
  71. * @param handler The callback handler which is invoked when the operation is complete,
  72. * with an error if there is any.
  73. */
  74. - (void)saveTokenInfo:(FIRInstanceIDTokenInfo *)tokenInfo handler:(void (^)(NSError *))handler;
  75. #pragma mark - Get
  76. /**
  77. * Get the cached token info.
  78. *
  79. * @param authorizedEntity The authorized entity for which we want the token.
  80. * @param scope The scope for which we want the token.
  81. *
  82. * @return The cached token info if any for the given authorizedEntity and scope else
  83. * returns nil.
  84. */
  85. - (nullable FIRInstanceIDTokenInfo *)tokenInfoWithAuthorizedEntity:(NSString *)authorizedEntity
  86. scope:(NSString *)scope;
  87. /**
  88. * Return all cached token infos from the Keychain.
  89. *
  90. * @return The cached token infos, if any, that are stored in the Keychain.
  91. */
  92. - (NSArray<FIRInstanceIDTokenInfo *> *)cachedTokenInfos;
  93. #pragma mark - Delete
  94. /**
  95. * Remove the cached token for a given authorizedEntity and scope. If the token was never
  96. * cached or deleted from the cache before this is a no-op.
  97. *
  98. * @param authorizedEntity The authorizedEntity for the cached token.
  99. * @param scope The scope for the cached token
  100. */
  101. - (void)removeCachedTokenWithAuthorizedEntity:(NSString *)authorizedEntity scope:(NSString *)scope;
  102. /**
  103. * Removes all cached tokens from the persistent store. In case deleting the cached tokens
  104. * fails we try to delete the backup excluded plist that stores the tokens.
  105. *
  106. * @param handler The callback handler which is invoked when the operation is complete,
  107. * with an error if there is any.
  108. *
  109. */
  110. - (void)removeAllCachedTokensWithHandler:(nullable void (^)(NSError *error))handler;
  111. #pragma mark - Persisting Checkin Preferences
  112. /**
  113. * Save the checkin preferences
  114. *
  115. * @param preferences Checkin preferences to save.
  116. * @param handler The callback handler which is invoked when the operation is complete,
  117. * with an error if there is any.
  118. */
  119. - (void)saveCheckinPreferences:(FIRInstanceIDCheckinPreferences *)preferences
  120. handler:(nullable void (^)(NSError *error))handler;
  121. /**
  122. * Return the cached checkin preferences.
  123. *
  124. * @return Checkin preferences.
  125. */
  126. - (FIRInstanceIDCheckinPreferences *)cachedCheckinPreferences;
  127. /**
  128. * Remove the cached checkin preferences from the store.
  129. *
  130. * @param handler The callback handler which is invoked when the operation is complete,
  131. * with an error if there is any.
  132. */
  133. - (void)removeCheckinPreferencesWithHandler:(nullable void (^)(NSError *error))handler;
  134. #pragma mark - Standard Directory sub-directory
  135. /**
  136. * Check if supported directory has InstanceID subdirectory
  137. *
  138. * @return YES if the Application Support directory has InstanceID subdirectory else NO.
  139. */
  140. + (BOOL)hasSubDirectory:(NSString *)subDirectoryName;
  141. /**
  142. * Create InstanceID subdirectory in Application support directory.
  143. *
  144. * @return YES if the subdirectory was created successfully else NO.
  145. */
  146. + (BOOL)createSubDirectory:(NSString *)subDirectoryName;
  147. /**
  148. * Removes Application Support subdirectory for InstanceID.
  149. *
  150. * @param error The error object if any while trying to delete the sub-directory.
  151. *
  152. * @return YES if the deletion was successful else NO.
  153. */
  154. + (BOOL)removeSubDirectory:(NSString *)subDirectoryName error:(NSError **)error;
  155. @end
  156. NS_ASSUME_NONNULL_END