FIRMessagingCheckinPreferences.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. FOUNDATION_EXPORT const NSTimeInterval kFIRMessagingDefaultCheckinInterval;
  18. /**
  19. * The preferences InstanceID loads from checkin server. The deviceID and secret that checkin
  20. * provides is used to authenticate all future requests to the server. Besides the deviceID
  21. * and secret the other information that checkin provides is stored in a plist on the device.
  22. * The deviceID and secret are persisted in the device keychain.
  23. */
  24. @interface FIRMessagingCheckinPreferences : NSObject
  25. /**
  26. * DeviceID and secretToken are the checkin auth credentials and are stored in the Keychain.
  27. */
  28. @property(nonatomic, readonly, copy) NSString *deviceID;
  29. @property(nonatomic, readonly, copy) NSString *secretToken;
  30. /**
  31. * All the other checkin preferences other than deviceID and secret are stored in a plist.
  32. */
  33. @property(nonatomic, readonly, copy) NSString *deviceDataVersion;
  34. @property(nonatomic, readonly, copy) NSString *digest;
  35. @property(nonatomic, readonly, copy) NSString *versionInfo;
  36. @property(nonatomic, readonly, assign) int64_t lastCheckinTimestampMillis;
  37. /**
  38. * The content retrieved from checkin server that should be persisted in a plist. This
  39. * doesn't contain the deviceID and secret which are stored in the Keychain since they
  40. * should be more private.
  41. *
  42. * @return The checkin preferences that should be persisted in a plist.
  43. */
  44. - (NSDictionary *)checkinPlistContents;
  45. /**
  46. * Return whether checkin info exists, valid or not.
  47. */
  48. - (BOOL)hasCheckinInfo;
  49. /**
  50. * Verify if checkin preferences are valid or not.
  51. *
  52. * @return YES if valid checkin preferences else NO.
  53. */
  54. - (BOOL)hasValidCheckinInfo;
  55. - (BOOL)hasPreCachedAuthCredentials;
  56. - (void)setHasPreCachedAuthCredentials:(BOOL)hasPreCachedAuthCredentials;
  57. /**
  58. * Parse the checkin auth credentials saved in the Keychain to initialize checkin
  59. * preferences.
  60. *
  61. * @param keychainContent The checkin auth credentials saved in the Keychain.
  62. *
  63. * @return A valid checkin preferences object if the checkin auth credentials in the
  64. * keychain can be parsed successfully else nil.
  65. */
  66. + (FIRMessagingCheckinPreferences *)preferencesFromKeychainContents:(NSString *)keychainContent;
  67. /**
  68. * Default initializer for InstanceID checkin preferences.
  69. *
  70. * @param deviceID The deviceID for the app.
  71. * @param secretToken The secret token the app uses to authenticate with the server.
  72. *
  73. * @return A checkin preferences object with given deviceID and secretToken.
  74. */
  75. - (instancetype)initWithDeviceID:(NSString *)deviceID secretToken:(NSString *)secretToken;
  76. /**
  77. * Update checkin preferences from the preferences dict persisted as a plist. The dict contains
  78. * all the checkin preferences retrieved from the server except the deviceID and secret which
  79. * are stored in the Keychain.
  80. *
  81. * @param checkinPlistContent The checkin preferences saved in a plist on the disk.
  82. */
  83. - (void)updateWithCheckinPlistContents:(NSDictionary *)checkinPlistContent;
  84. /**
  85. * Reset the current checkin preferences object.
  86. */
  87. - (void)reset;
  88. /**
  89. * The string that contains the checkin auth credentials i.e. deviceID and secret. This
  90. * needs to be stored in the Keychain.
  91. *
  92. * @return The checkin auth credential string containing the deviceID and secret.
  93. */
  94. - (NSString *)checkinKeychainContent;
  95. @end