From b9c35c4fd209072ee46f6ed14478b56c2128e0ac Mon Sep 17 00:00:00 2001 From: Cynthia Jiang Date: Tue, 6 Apr 2021 16:23:32 -0700 Subject: [PATCH 1/3] Change GKLocalPlayer to be runtime referenced --- auth/src/ios/credential_ios.mm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/auth/src/ios/credential_ios.mm b/auth/src/ios/credential_ios.mm index 0ed1e252ba..6eb7d99a2a 100644 --- a/auth/src/ios/credential_ios.mm +++ b/auth/src/ios/credential_ios.mm @@ -166,9 +166,16 @@ @implementation PhoneListenerDataObjC FIREBASE_ASSERT(future_api != nullptr); const auto handle = future_api->SafeAlloc(kCredentialFn_GameCenterGetCredential); + /** + Linking GameKit.framework without using it on macOS results in App Store rejection. + Thus we don't link GameKit.framework to our SDK directly. `optionalLocalPlayer` is used for + checking whether the APP that consuming our SDK has linked GameKit.framework. If not, a + `GameKitNotLinkedError` will be raised. + **/ + GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init]; // Early-out if GameKit is not linked - if ([GKLocalPlayer class] == nullptr) { + if (optionalLocalPlayer == nullptr) { future_api->Complete(handle, kAuthErrorInvalidCredential, "GameCenter authentication is unavailable - missing GameKit capability."); return MakeFuture(future_api, handle); @@ -197,11 +204,18 @@ @implementation PhoneListenerDataObjC // static bool GameCenterAuthProvider::IsPlayerAuthenticated() { + /** + Linking GameKit.framework without using it on macOS results in App Store rejection. + Thus we don't link GameKit.framework to our SDK directly. `optionalLocalPlayer` is used for + checking whether the APP that consuming our SDK has linked GameKit.framework. If not, a + `GameKitNotLinkedError` will be raised. + **/ + GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init]; // If the GameKit Framework isn't linked - early out. - if ([GKLocalPlayer class] == nullptr) { + if (optionalLocalPlayer == nullptr) { return false; } - GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; + __weak GKLocalPlayer *localPlayer = [[optionalLocalPlayer class] localPlayer]; return localPlayer.isAuthenticated; } From 33fa78a8fcdffe3b1e97f5311e628396c1aa80e2 Mon Sep 17 00:00:00 2001 From: Cynthia Jiang Date: Tue, 6 Apr 2021 16:28:04 -0700 Subject: [PATCH 2/3] Tweak the comments --- auth/src/ios/credential_ios.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/auth/src/ios/credential_ios.mm b/auth/src/ios/credential_ios.mm index 6eb7d99a2a..4d87bf1f63 100644 --- a/auth/src/ios/credential_ios.mm +++ b/auth/src/ios/credential_ios.mm @@ -169,8 +169,8 @@ @implementation PhoneListenerDataObjC /** Linking GameKit.framework without using it on macOS results in App Store rejection. Thus we don't link GameKit.framework to our SDK directly. `optionalLocalPlayer` is used for - checking whether the APP that consuming our SDK has linked GameKit.framework. If not, a - `GameKitNotLinkedError` will be raised. + checking whether the APP that consuming our SDK has linked GameKit.framework. If not, will + complete with kAuthErrorInvalidCredential error. **/ GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init]; @@ -207,8 +207,8 @@ @implementation PhoneListenerDataObjC /** Linking GameKit.framework without using it on macOS results in App Store rejection. Thus we don't link GameKit.framework to our SDK directly. `optionalLocalPlayer` is used for - checking whether the APP that consuming our SDK has linked GameKit.framework. If not, a - `GameKitNotLinkedError` will be raised. + checking whether the APP that consuming our SDK has linked GameKit.framework. If not, + early out. **/ GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init]; // If the GameKit Framework isn't linked - early out. From 005633e7f559763f5884de2a074c71f1575f78a0 Mon Sep 17 00:00:00 2001 From: Cynthia Jiang Date: Wed, 7 Apr 2021 17:20:38 -0700 Subject: [PATCH 3/3] address review comments --- auth/src/ios/credential_ios.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth/src/ios/credential_ios.mm b/auth/src/ios/credential_ios.mm index 4d87bf1f63..e518f59310 100644 --- a/auth/src/ios/credential_ios.mm +++ b/auth/src/ios/credential_ios.mm @@ -175,7 +175,7 @@ @implementation PhoneListenerDataObjC GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init]; // Early-out if GameKit is not linked - if (optionalLocalPlayer == nullptr) { + if (!optionalLocalPlayer) { future_api->Complete(handle, kAuthErrorInvalidCredential, "GameCenter authentication is unavailable - missing GameKit capability."); return MakeFuture(future_api, handle); @@ -212,7 +212,7 @@ @implementation PhoneListenerDataObjC **/ GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init]; // If the GameKit Framework isn't linked - early out. - if (optionalLocalPlayer == nullptr) { + if (!optionalLocalPlayer) { return false; } __weak GKLocalPlayer *localPlayer = [[optionalLocalPlayer class] localPlayer];