Skip to content

Commit a2e13d5

Browse files
author
Chuan Ren
authored
Resolve hard dependency of GameKit (#2355)
1 parent 9be3038 commit a2e13d5

File tree

5 files changed

+46
-2
lines changed

5 files changed

+46
-2
lines changed

Firebase/Auth/Source/AuthProviders/GameCenter/FIRGameCenterAuthProvider.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,22 @@ - (instancetype)init {
3131
}
3232

3333
+ (void)getCredentialWithCompletion:(FIRGameCenterCredentialCallback)completion {
34-
__weak GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
34+
/**
35+
Linking GameKit.framework without using it on macOS results in App Store rejection.
36+
Thus we don't link GameKit.framework to our SDK directly. `optionalLocalPlayer` is used for
37+
checking whether the APP that consuming our SDK has linked GameKit.framework. If not, a
38+
`GameKitNotLinkedError` will be raised.
39+
**/
40+
GKLocalPlayer *optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init];
41+
42+
if (!optionalLocalPlayer) {
43+
if (completion) {
44+
completion(nil, [FIRAuthErrorUtils gameKitNotLinkedError]);
45+
}
46+
return;
47+
}
48+
49+
__weak GKLocalPlayer *localPlayer = [[optionalLocalPlayer class] localPlayer];
3550
if (!localPlayer.isAuthenticated) {
3651
if (completion) {
3752
completion(nil, [FIRAuthErrorUtils localPlayerNotAuthenticatedError]);

Firebase/Auth/Source/FIRAuthErrorUtils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,12 @@ NS_ASSUME_NONNULL_BEGIN
451451
*/
452452
+ (NSError *)localPlayerNotAuthenticatedError;
453453

454+
/** @fn gameKitNotLinkedError
455+
@brief Constructs an @c NSError with the @c FIRAuthErrorCodeGameKitNotLinked code.
456+
@return The NSError instance associated with the given FIRAuthError.
457+
*/
458+
+ (NSError *)gameKitNotLinkedError;
459+
454460
/** @fn notificationNotForwardedError
455461
@brief Constructs an @c NSError with the @c FIRAuthErrorCodeNotificationNotForwarded code.
456462
@return The NSError instance associated with the given FIRAuthError.

Firebase/Auth/Source/FIRAuthErrorUtils.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,17 @@
312312
@"The verification ID used to create the phone auth credential is invalid.";
313313

314314
/** @var kFIRAuthErrorMessageLocalPlayerNotAuthenticated
315-
@brief Message for @c FIRAuthErrorCodeLocalPlayerNotAuthenticated error code.
315+
@brief Message for @c FIRAuthErrorCodeLocalPlayerNotAuthenticated error code.
316316
*/
317317
static NSString *const kFIRAuthErrorMessageLocalPlayerNotAuthenticated =
318318
@"The local player is not authenticated. Please log the local player in to Game Center.";
319319

320+
/** @var kFIRAuthErrorMessageGameKitNotLinked
321+
@brief Message for @c kFIRAuthErrorMessageGameKitNotLinked error code.
322+
*/
323+
static NSString *const kFIRAuthErrorMessageGameKitNotLinked =
324+
@"The GameKit framework is not linked. Please turn on the Game Center capability.";
325+
320326
/** @var kFIRAuthErrorMessageSessionExpired
321327
@brief Message for @c FIRAuthErrorCodeSessionExpired error code.
322328
*/
@@ -556,6 +562,8 @@
556562
return kFIRAuthErrorMessageMalformedJWT;
557563
case FIRAuthErrorCodeLocalPlayerNotAuthenticated:
558564
return kFIRAuthErrorMessageLocalPlayerNotAuthenticated;
565+
case FIRAuthErrorCodeGameKitNotLinked:
566+
return kFIRAuthErrorMessageGameKitNotLinked;
559567
}
560568
}
561569

@@ -683,6 +691,8 @@
683691
return @"ERROR_MALFORMED_JWT";
684692
case FIRAuthErrorCodeLocalPlayerNotAuthenticated:
685693
return @"ERROR_LOCAL_PLAYER_NOT_AUTHENTICATED";
694+
case FIRAuthErrorCodeGameKitNotLinked:
695+
return @"ERROR_GAME_KIT_NOT_LINKED";
686696
}
687697
}
688698

@@ -1000,6 +1010,10 @@ + (NSError *)localPlayerNotAuthenticatedError {
10001010
return [self errorWithCode:FIRAuthInternalErrorCodeLocalPlayerNotAuthenticated];
10011011
}
10021012

1013+
+ (NSError *)gameKitNotLinkedError {
1014+
return [self errorWithCode:FIRAuthInternalErrorCodeGameKitNotLinked];
1015+
}
1016+
10031017
+ (NSError *)notificationNotForwardedError {
10041018
return [self errorWithCode:FIRAuthInternalErrorCodeNotificationNotForwarded];
10051019
}

Firebase/Auth/Source/FIRAuthInternalErrors.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ typedef NS_ENUM(NSInteger, FIRAuthInternalErrorCode) {
375375
FIRAuthInternalErrorCodeLocalPlayerNotAuthenticated =
376376
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeLocalPlayerNotAuthenticated,
377377

378+
/** Indicates that the Game Center local player was not authenticated.
379+
*/
380+
FIRAuthInternalErrorCodeGameKitNotLinked =
381+
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeGameKitNotLinked,
382+
378383
/** Indicates that a non-null user was expected as an argmument to the operation but a null
379384
user was provided.
380385
*/

Firebase/Auth/Source/Public/FIRAuthErrors.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ typedef NS_ENUM(NSInteger, FIRAuthErrorCode) {
313313
*/
314314
FIRAuthErrorCodeInvalidDynamicLinkDomain = 17074,
315315

316+
/** Indicates that the GameKit framework is not linked prior to attempting Game Center signin.
317+
*/
318+
FIRAuthErrorCodeGameKitNotLinked = 17076,
319+
316320
/** Indicates an error occurred while attempting to access the keychain.
317321
*/
318322
FIRAuthErrorCodeKeychainError = 17995,

0 commit comments

Comments
 (0)