Ingen beskrivning

FIRUserInfoImpl.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright 2017 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 "FIRUserInfoImpl.h"
  17. #import "FIRGetAccountInfoResponse.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** @var kProviderIDCodingKey
  20. @brief The key used to encode the providerID property for NSSecureCoding.
  21. */
  22. static NSString *const kProviderIDCodingKey = @"providerID";
  23. /** @var kUserIDCodingKey
  24. @brief The key used to encode the userID property for NSSecureCoding.
  25. */
  26. static NSString *const kUserIDCodingKey = @"userID";
  27. /** @var kDisplayNameCodingKey
  28. @brief The key used to encode the displayName property for NSSecureCoding.
  29. */
  30. static NSString *const kDisplayNameCodingKey = @"displayName";
  31. /** @var kProfileURLCodingKey
  32. @brief The key used to encode the profileURL property for NSSecureCoding.
  33. */
  34. static NSString *const kProfileURLCodingKey = @"profileURL";
  35. /** @var kPhotoURLCodingKey
  36. @brief The key used to encode the photoURL property for NSSecureCoding.
  37. */
  38. static NSString *const kPhotoURLCodingKey = @"photoURL";
  39. /** @var kEmailCodingKey
  40. @brief The key used to encode the email property for NSSecureCoding.
  41. */
  42. static NSString *const kEmailCodingKey = @"email";
  43. /** @var kPhoneNumberCodingKey
  44. @brief The key used to encode the phoneNumber property for NSSecureCoding.
  45. */
  46. static NSString *const kPhoneNumberCodingKey = @"phoneNumber";
  47. @implementation FIRUserInfoImpl
  48. @synthesize providerID = _providerID;
  49. @synthesize uid = _userID;
  50. @synthesize displayName = _displayName;
  51. @synthesize photoURL = _photoURL;
  52. @synthesize email = _email;
  53. @synthesize phoneNumber = _phoneNumber;
  54. + (nullable instancetype)userInfoWithGetAccountInfoResponseProviderUserInfo:
  55. (FIRGetAccountInfoResponseProviderUserInfo *)providerUserInfo {
  56. return [[self alloc] initWithProviderID:providerUserInfo.providerID
  57. userID:providerUserInfo.federatedID
  58. displayName:providerUserInfo.displayName
  59. photoURL:providerUserInfo.photoURL
  60. email:providerUserInfo.email
  61. phoneNumber:providerUserInfo.phoneNumber];
  62. }
  63. - (nullable instancetype)initWithProviderID:(NSString *)providerID
  64. userID:(NSString *)userID
  65. displayName:(nullable NSString *)displayName
  66. photoURL:(nullable NSURL *)photoURL
  67. email:(nullable NSString *)email
  68. phoneNumber:(nullable NSString *)phoneNumber {
  69. self = [super init];
  70. if (self) {
  71. _providerID = [providerID copy];
  72. _userID = [userID copy];
  73. _displayName = [displayName copy];
  74. _photoURL = [photoURL copy];
  75. _email = [email copy];
  76. _phoneNumber = [phoneNumber copy];
  77. }
  78. return self;
  79. }
  80. #pragma mark - NSSecureCoding
  81. + (BOOL)supportsSecureCoding {
  82. return YES;
  83. }
  84. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  85. NSString *providerID =
  86. [aDecoder decodeObjectOfClass:[NSString class] forKey:kProviderIDCodingKey];
  87. NSString *userID = [aDecoder decodeObjectOfClass:[NSString class] forKey:kUserIDCodingKey];
  88. NSString *displayName =
  89. [aDecoder decodeObjectOfClass:[NSString class] forKey:kDisplayNameCodingKey];
  90. NSURL *photoURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:kPhotoURLCodingKey];
  91. NSString *email = [aDecoder decodeObjectOfClass:[NSString class] forKey:kEmailCodingKey];
  92. NSString *phoneNumber =
  93. [aDecoder decodeObjectOfClass:[NSString class] forKey:kPhoneNumberCodingKey];
  94. return [self initWithProviderID:providerID
  95. userID:userID
  96. displayName:displayName
  97. photoURL:photoURL
  98. email:email
  99. phoneNumber:phoneNumber];
  100. }
  101. - (void)encodeWithCoder:(NSCoder *)aCoder {
  102. [aCoder encodeObject:_providerID forKey:kProviderIDCodingKey];
  103. [aCoder encodeObject:_userID forKey:kUserIDCodingKey];
  104. [aCoder encodeObject:_displayName forKey:kDisplayNameCodingKey];
  105. [aCoder encodeObject:_photoURL forKey:kPhotoURLCodingKey];
  106. [aCoder encodeObject:_email forKey:kEmailCodingKey];
  107. [aCoder encodeObject:_phoneNumber forKey:kPhoneNumberCodingKey];
  108. }
  109. @end
  110. NS_ASSUME_NONNULL_END