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