Skip to content

Commit 6fbd7b9

Browse files
authored
Update deprecated archiving API usage (#449)
1 parent de6e893 commit 6fbd7b9

File tree

6 files changed

+59
-13
lines changed

6 files changed

+59
-13
lines changed

GoogleSignIn/Sources/GIDSignInButton.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,17 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
230230
}
231231

232232
- (void)encodeWithCoder:(NSCoder *)aCoder {
233-
[super encodeWithCoder:aCoder];
234233
[aCoder encodeInteger:_style forKey:kStyleKey];
235234
[aCoder encodeInteger:_colorScheme forKey:kColorSchemeKey];
236235
[aCoder encodeInteger:_buttonState forKey:kButtonState];
237236
}
238237

238+
#pragma mark - NSSecureCoding
239+
240+
+ (BOOL)supportsSecureCoding {
241+
return YES;
242+
}
243+
239244
#pragma mark - UI
240245

241246
- (void)updateUI {

GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignInButton.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef NS_ENUM(NSInteger, GIDSignInButtonColorScheme) {
4646
/// control to an `IBAction`, or something similar, that calls
4747
/// signInWithPresentingViewController:completion: on `GIDSignIn` and add it to your view
4848
/// hierarchy.
49-
@interface GIDSignInButton : UIControl
49+
@interface GIDSignInButton : UIControl <NSSecureCoding>
5050

5151
/// The layout style for the sign-in button.
5252
/// Possible values:

GoogleSignIn/Tests/Unit/GIDConfigurationTest.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,17 @@ - (void)testCoding {
9999
// Deprecated in iOS 13 and macOS 10.14
100100
- (void)testLegacyCoding {
101101
GIDConfiguration *configuration = [GIDConfiguration testInstance];
102-
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:configuration];
103-
GIDConfiguration *newConfiguration = [NSKeyedUnarchiver unarchiveObjectWithData:data];
104-
XCTAssertEqualObjects(configuration, newConfiguration);
102+
NSError *archivedError;
103+
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:configuration
104+
requiringSecureCoding:NO
105+
error:&archivedError];
106+
XCTAssertNil(archivedError);
107+
NSError *unArchivedError;
108+
GIDConfiguration *newConfig = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDConfiguration class]
109+
fromData:data
110+
error:&unArchivedError];
111+
XCTAssertNil(unArchivedError);
112+
XCTAssertEqualObjects(configuration, newConfig);
105113
XCTAssertTrue(GIDConfiguration.supportsSecureCoding);
106114
}
107115
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST

GoogleSignIn/Tests/Unit/GIDGoogleUserTest.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,17 @@ - (void)testCoding {
133133
- (void)testLegacyCoding {
134134
GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:[OIDAuthState testInstance]
135135
profileData:[GIDProfileData testInstance]];
136-
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user];
137-
GIDGoogleUser *newUser = [NSKeyedUnarchiver unarchiveObjectWithData:data];
136+
137+
NSError *archiveError;
138+
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user
139+
requiringSecureCoding:NO
140+
error:&archiveError];
141+
XCTAssertNil(archiveError);
142+
NSError *unarchiveError;
143+
GIDGoogleUser *newUser = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDGoogleUser class]
144+
fromData:data
145+
error:&unarchiveError];
146+
XCTAssertNil(unarchiveError);
138147
XCTAssertEqualObjects(user, newUser);
139148
XCTAssertTrue(GIDGoogleUser.supportsSecureCoding);
140149
}

GoogleSignIn/Tests/Unit/GIDProfileDataTest.m

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,16 @@ - (void)testOldArchiveFormat {
138138
// Deprecated in iOS 13 and macOS 10.14
139139
- (void)testLegacyCoding {
140140
GIDProfileData *profileData = [self profileData];
141-
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profileData];
142-
GIDProfileData *newProfileData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
141+
NSError *archiveError;
142+
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profileData
143+
requiringSecureCoding:NO
144+
error:&archiveError];
145+
XCTAssertNil(archiveError);
146+
NSError *unarchiveError;
147+
GIDProfileData *newProfileData = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDProfileData class]
148+
fromData:data
149+
error:&unarchiveError];
150+
XCTAssertNil(unarchiveError);
143151
XCTAssertEqualObjects(profileData, newProfileData);
144152
XCTAssertTrue(GIDProfileData.supportsSecureCoding);
145153
}
@@ -149,8 +157,16 @@ - (void)testOldArchiveFormatLegacy {
149157
name:kName
150158
imageURL:kFIFEImageURL];
151159
[NSKeyedArchiver setClassName:@"GIDProfileData" forClass:[GIDProfileDataOld class]];
152-
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:oldProfile];
153-
GIDProfileData *profileData = [NSKeyedUnarchiver unarchiveObjectWithData:data];
160+
NSError *archiveError;
161+
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:oldProfile
162+
requiringSecureCoding:NO
163+
error:&archiveError];
164+
XCTAssertNil(archiveError);
165+
NSError *unarchiveError;
166+
GIDProfileData *profileData = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDProfileData class]
167+
fromData:data
168+
error:&unarchiveError];
169+
XCTAssertNil(unarchiveError);
154170
XCTAssertEqualObjects(profileData.email, kEmail);
155171
XCTAssertEqualObjects(profileData.name, kName);
156172
XCTAssertNil(profileData.givenName);

GoogleSignIn/Tests/Unit/GIDSignInButtonTest.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,16 @@ - (void)testNSCoding {
7373
GIDSignInButton *button = [[GIDSignInButton alloc] init];
7474
button.style = kGIDSignInButtonStyleIconOnly;
7575
button.colorScheme = kGIDSignInButtonColorSchemeLight;
76-
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:button];
77-
GIDSignInButton *newButton = [NSKeyedUnarchiver unarchiveObjectWithData:data];
76+
NSError *archiveError;
77+
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:button
78+
requiringSecureCoding:NO
79+
error:&archiveError];
80+
XCTAssertNil(archiveError);
81+
NSError *unarchiveError;
82+
GIDSignInButton *newButton = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDSignInButton class]
83+
fromData:data
84+
error:&unarchiveError];
85+
XCTAssertNil(unarchiveError);
7886
XCTAssertEqual(button.style, newButton.style);
7987
XCTAssertEqual(button.colorScheme, newButton.colorScheme);
8088
}

0 commit comments

Comments
 (0)