FIRInstallationsStoredItem.m 3.3 KB

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