FIRInstallationsStoredRegistrationParameters.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "FIRInstallationsStoredRegistrationParameters.h"
  17. #import "FIRInstallationsLogger.h"
  18. NSString *const kFIRInstallationsStoredRegistrationParametersAPIKeyKey = @"APIKey";
  19. NSString *const kFIRInstallationsStoredRegistrationParametersProjectID = @"projectID";
  20. NSString *const FIRInstallationsStoredRegistrationParametersStorageVersionKey = @"storageVersion";
  21. NSInteger const FIRInstallationsStoredRegistrationParametersStorageVersion = 1;
  22. @implementation FIRInstallationsStoredRegistrationParameters
  23. - (instancetype)initWithAPIKey:(NSString *)APIKey projectID:(NSString *)projectID {
  24. self = [super init];
  25. if (self) {
  26. _APIKey = APIKey;
  27. _projectID = projectID;
  28. }
  29. return self;
  30. }
  31. - (NSInteger)storageVersion {
  32. return FIRInstallationsStoredRegistrationParametersStorageVersion;
  33. }
  34. #pragma mark - NSSecureCoding
  35. + (BOOL)supportsSecureCoding {
  36. return YES;
  37. }
  38. - (void)encodeWithCoder:(nonnull NSCoder *)coder {
  39. [coder encodeObject:self.APIKey forKey:kFIRInstallationsStoredRegistrationParametersAPIKeyKey];
  40. [coder encodeObject:self.projectID forKey:kFIRInstallationsStoredRegistrationParametersProjectID];
  41. [coder encodeInteger:self.storageVersion
  42. forKey:FIRInstallationsStoredRegistrationParametersStorageVersionKey];
  43. }
  44. - (nullable instancetype)initWithCoder:(nonnull NSCoder *)coder {
  45. NSInteger storageVersion =
  46. [coder decodeIntegerForKey:FIRInstallationsStoredRegistrationParametersStorageVersionKey];
  47. if (storageVersion > self.storageVersion) {
  48. FIRLogWarning(kFIRLoggerInstallations,
  49. kFIRInstallationsMessageCodeRegistrationParametersCoderVersionMismatch,
  50. @"FIRInstallationsStoredRegistrationParameters was encoded by a newer coder "
  51. @"version %ld. Current coder version is %ld. Some installation data may be lost.",
  52. (long)storageVersion, (long)self.storageVersion);
  53. }
  54. NSString *APIKey =
  55. [coder decodeObjectForKey:kFIRInstallationsStoredRegistrationParametersAPIKeyKey];
  56. NSString *projectID =
  57. [coder decodeObjectForKey:kFIRInstallationsStoredRegistrationParametersProjectID];
  58. return [self initWithAPIKey:APIKey projectID:projectID];
  59. }
  60. @end