FIRInstallationsStoredItem.m 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredItem.h"
  17. #import "FirebaseInstallations/Source/Library/FIRInstallationsLogger.h"
  18. #import "FirebaseInstallations/Source/Library/InstallationsStore/FIRInstallationsStoredAuthToken.h"
  19. NSString *const kFIRInstallationsStoredItemFirebaseInstallationIDKey = @"firebaseInstallationID";
  20. NSString *const kFIRInstallationsStoredItemRefreshTokenKey = @"refreshToken";
  21. NSString *const kFIRInstallationsStoredItemAuthTokenKey = @"authToken";
  22. NSString *const kFIRInstallationsStoredItemRegistrationStatusKey = @"registrationStatus";
  23. NSString *const kFIRInstallationsStoredItemIIDDefaultTokenKey = @"IIDDefaultToken";
  24. NSString *const kFIRInstallationsStoredItemStorageVersionKey = @"storageVersion";
  25. NSInteger const kFIRInstallationsStoredItemStorageVersion = 1;
  26. @implementation FIRInstallationsStoredItem
  27. - (NSInteger)storageVersion {
  28. return kFIRInstallationsStoredItemStorageVersion;
  29. }
  30. - (void)encodeWithCoder:(nonnull NSCoder *)aCoder {
  31. [aCoder encodeObject:self.firebaseInstallationID
  32. forKey:kFIRInstallationsStoredItemFirebaseInstallationIDKey];
  33. [aCoder encodeObject:self.refreshToken forKey:kFIRInstallationsStoredItemRefreshTokenKey];
  34. [aCoder encodeObject:self.authToken forKey:kFIRInstallationsStoredItemAuthTokenKey];
  35. [aCoder encodeInteger:self.registrationStatus
  36. forKey:kFIRInstallationsStoredItemRegistrationStatusKey];
  37. [aCoder encodeObject:self.IIDDefaultToken forKey:kFIRInstallationsStoredItemIIDDefaultTokenKey];
  38. [aCoder encodeInteger:self.storageVersion forKey:kFIRInstallationsStoredItemStorageVersionKey];
  39. }
  40. - (nullable instancetype)initWithCoder:(nonnull NSCoder *)aDecoder {
  41. NSInteger storageVersion =
  42. [aDecoder decodeIntegerForKey:kFIRInstallationsStoredItemStorageVersionKey];
  43. if (storageVersion > self.storageVersion) {
  44. FIRLogWarning(kFIRLoggerInstallations,
  45. kFIRInstallationsMessageCodeInstallationCoderVersionMismatch,
  46. @"FIRInstallationsStoredItem was encoded by a newer coder version %ld. Current "
  47. @"coder version is %ld. Some installation data may be lost.",
  48. (long)storageVersion, (long)kFIRInstallationsStoredItemStorageVersion);
  49. }
  50. FIRInstallationsStoredItem *item = [[FIRInstallationsStoredItem alloc] init];
  51. item.firebaseInstallationID =
  52. [aDecoder decodeObjectOfClass:[NSString class]
  53. forKey:kFIRInstallationsStoredItemFirebaseInstallationIDKey];
  54. item.refreshToken = [aDecoder decodeObjectOfClass:[NSString class]
  55. forKey:kFIRInstallationsStoredItemRefreshTokenKey];
  56. item.authToken = [aDecoder decodeObjectOfClass:[FIRInstallationsStoredAuthToken class]
  57. forKey:kFIRInstallationsStoredItemAuthTokenKey];
  58. item.registrationStatus =
  59. [aDecoder decodeIntegerForKey:kFIRInstallationsStoredItemRegistrationStatusKey];
  60. item.IIDDefaultToken =
  61. [aDecoder decodeObjectOfClass:[NSString class]
  62. forKey:kFIRInstallationsStoredItemIIDDefaultTokenKey];
  63. return item;
  64. }
  65. + (BOOL)supportsSecureCoding {
  66. return YES;
  67. }
  68. @end