FIRMessagingTokenInfo.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #import "FirebaseMessaging/Sources/Token/FIRMessagingAPNSInfo.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /**
  20. * Represents an Instance ID token, and all of the relevant information
  21. * associated with it. It can read from and write to an NSDictionary object, for
  22. * simple serialization.
  23. */
  24. @interface FIRMessagingTokenInfo : NSObject <NSSecureCoding>
  25. /// The authorized entity (also known as Sender ID), associated with the token.
  26. @property(nonatomic, readonly, copy) NSString *authorizedEntity;
  27. /// The scope associated with the token. This is an arbitrary string, typically "*".
  28. @property(nonatomic, readonly, copy) NSString *scope;
  29. /// The token value itself, with which all other properties are associated.
  30. @property(nonatomic, readonly, copy) NSString *token;
  31. // These properties are nullable because they might not exist for tokens fetched from
  32. // legacy storage formats.
  33. /// The app version that this token represents.
  34. @property(nonatomic, readonly, copy, nullable) NSString *appVersion;
  35. /// The Firebase app ID (also known as GMP App ID), that this token is associated with.
  36. @property(nonatomic, readonly, copy, nullable) NSString *firebaseAppID;
  37. /// Tokens may not always be associated with an APNs token, and may be associated after
  38. /// being created.
  39. @property(nonatomic, strong, nullable) FIRMessagingAPNSInfo *APNSInfo;
  40. /// The time that this token info was updated. The cache time is writeable, since in
  41. /// some cases the token info may be refreshed from the server. In those situations,
  42. /// the cacheTime would be updated.
  43. @property(nonatomic, copy, nullable) NSDate *cacheTime;
  44. /// Indicates the info was stored on the keychain by version 10.18.0 or earlier.
  45. @property(nonatomic, readonly) BOOL needsMigration;
  46. /**
  47. * Initializes a FIRMessagingTokenInfo object with the required parameters. These
  48. * parameters represent all the relevant associated data with a token.
  49. *
  50. * @param authorizedEntity The authorized entity (also known as Sender ID).
  51. * @param scope The scope of the token, typically "*" meaning
  52. * it's a "default scope".
  53. * @param token The token value itself.
  54. * @param appVersion The application version that this token is associated with.
  55. * @param firebaseAppID The Firebase app ID which this token is associated with.
  56. * @return An instance of FIRMessagingTokenInfo.
  57. */
  58. - (instancetype)initWithAuthorizedEntity:(NSString *)authorizedEntity
  59. scope:(NSString *)scope
  60. token:(NSString *)token
  61. appVersion:(nullable NSString *)appVersion
  62. firebaseAppID:(nullable NSString *)firebaseAppID;
  63. /**
  64. * Check whether the token is still fresh based on:
  65. * 1. Last fetch token is within the 7 days.
  66. * 2. Language setting is not changed.
  67. * 3. App version is current.
  68. * 4. GMP App ID is current.
  69. * 5. token is consistent with the current IID.
  70. * 6. APNS info has changed.
  71. * @param IID The app identifiier that is used to check if token is prefixed with.
  72. * @return If token is fresh.
  73. *
  74. */
  75. - (BOOL)isFreshWithIID:(NSString *)IID;
  76. /*
  77. * Check whether the token is default token.
  78. */
  79. - (BOOL)isDefaultToken;
  80. @end
  81. NS_ASSUME_NONNULL_END