Skip to content

Commit

Permalink
Update deprecated archiving API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmathias committed Jun 17, 2024
1 parent 14b8cef commit 8c1b610
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 13 deletions.
7 changes: 6 additions & 1 deletion GoogleSignIn/Sources/GIDSignInButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,17 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
[super encodeWithCoder:aCoder];
[aCoder encodeInteger:_style forKey:kStyleKey];
[aCoder encodeInteger:_colorScheme forKey:kColorSchemeKey];
[aCoder encodeInteger:_buttonState forKey:kButtonState];
}

#pragma mark - NSSecureCoding

+ (BOOL)supportsSecureCoding {
return YES;
}

#pragma mark - UI

- (void)updateUI {
Expand Down
2 changes: 1 addition & 1 deletion GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef NS_ENUM(NSInteger, GIDSignInButtonColorScheme) {
/// control to an `IBAction`, or something similar, that calls
/// signInWithPresentingViewController:completion: on `GIDSignIn` and add it to your view
/// hierarchy.
@interface GIDSignInButton : UIControl
@interface GIDSignInButton : UIControl <NSSecureCoding>

/// The layout style for the sign-in button.
/// Possible values:
Expand Down
14 changes: 11 additions & 3 deletions GoogleSignIn/Tests/Unit/GIDConfigurationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,17 @@ - (void)testCoding {
// Deprecated in iOS 13 and macOS 10.14
- (void)testLegacyCoding {
GIDConfiguration *configuration = [GIDConfiguration testInstance];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:configuration];
GIDConfiguration *newConfiguration = [NSKeyedUnarchiver unarchiveObjectWithData:data];
XCTAssertEqualObjects(configuration, newConfiguration);
NSError *archivedError;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:configuration
requiringSecureCoding:NO
error:&archivedError];
XCTAssertNil(archivedError);
NSError *unArchivedError;
GIDConfiguration *newConfig = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDConfiguration class]
fromData:data
error:&unArchivedError];
XCTAssertNil(unArchivedError);
XCTAssertEqualObjects(configuration, newConfig);
XCTAssertTrue(GIDConfiguration.supportsSecureCoding);
}
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
Expand Down
13 changes: 11 additions & 2 deletions GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,17 @@ - (void)testCoding {
- (void)testLegacyCoding {
GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:[OIDAuthState testInstance]
profileData:[GIDProfileData testInstance]];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user];
GIDGoogleUser *newUser = [NSKeyedUnarchiver unarchiveObjectWithData:data];

NSError *archiveError;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user
requiringSecureCoding:NO
error:&archiveError];
XCTAssertNil(archiveError);
NSError *unarchiveError;
GIDGoogleUser *newUser = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDGoogleUser class]
fromData:data
error:&unarchiveError];
XCTAssertNil(unarchiveError);
XCTAssertEqualObjects(user, newUser);
XCTAssertTrue(GIDGoogleUser.supportsSecureCoding);
}
Expand Down
24 changes: 20 additions & 4 deletions GoogleSignIn/Tests/Unit/GIDProfileDataTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,16 @@ - (void)testOldArchiveFormat {
// Deprecated in iOS 13 and macOS 10.14
- (void)testLegacyCoding {
GIDProfileData *profileData = [self profileData];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profileData];
GIDProfileData *newProfileData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSError *archiveError;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profileData
requiringSecureCoding:NO
error:&archiveError];
XCTAssertNil(archiveError);
NSError *unarchiveError;
GIDProfileData *newProfileData = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDProfileData class]
fromData:data
error:&unarchiveError];
XCTAssertNil(unarchiveError);
XCTAssertEqualObjects(profileData, newProfileData);
XCTAssertTrue(GIDProfileData.supportsSecureCoding);
}
Expand All @@ -149,8 +157,16 @@ - (void)testOldArchiveFormatLegacy {
name:kName
imageURL:kFIFEImageURL];
[NSKeyedArchiver setClassName:@"GIDProfileData" forClass:[GIDProfileDataOld class]];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:oldProfile];
GIDProfileData *profileData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSError *archiveError;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:oldProfile
requiringSecureCoding:NO
error:&archiveError];
XCTAssertNil(archiveError);
NSError *unarchiveError;
GIDProfileData *profileData = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDProfileData class]
fromData:data
error:&unarchiveError];
XCTAssertNil(unarchiveError);
XCTAssertEqualObjects(profileData.email, kEmail);
XCTAssertEqualObjects(profileData.name, kName);
XCTAssertNil(profileData.givenName);
Expand Down
12 changes: 10 additions & 2 deletions GoogleSignIn/Tests/Unit/GIDSignInButtonTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ - (void)testNSCoding {
GIDSignInButton *button = [[GIDSignInButton alloc] init];
button.style = kGIDSignInButtonStyleIconOnly;
button.colorScheme = kGIDSignInButtonColorSchemeLight;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:button];
GIDSignInButton *newButton = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSError *archiveError;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:button
requiringSecureCoding:NO
error:&archiveError];
XCTAssertNil(archiveError);
NSError *unarchiveError;
GIDSignInButton *newButton = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDSignInButton class]
fromData:data
error:&unarchiveError];
XCTAssertNil(unarchiveError);
XCTAssertEqual(button.style, newButton.style);
XCTAssertEqual(button.colorScheme, newButton.colorScheme);
}
Expand Down

0 comments on commit 8c1b610

Please sign in to comment.