Skip to content

Change GKLocalPlayer to be runtime referenced #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions auth/src/ios/credential_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,16 @@ @implementation PhoneListenerDataObjC
FIREBASE_ASSERT(future_api != nullptr);

const auto handle = future_api->SafeAlloc<Credential>(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, will
complete with kAuthErrorInvalidCredential error.
**/
GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init];

// Early-out if GameKit is not linked
if ([GKLocalPlayer class] == nullptr) {
if (!optionalLocalPlayer) {
future_api->Complete(handle, kAuthErrorInvalidCredential,
"GameCenter authentication is unavailable - missing GameKit capability.");
return MakeFuture(future_api, handle);
Expand Down Expand Up @@ -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,
early out.
**/
GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init];
// If the GameKit Framework isn't linked - early out.
if ([GKLocalPlayer class] == nullptr) {
if (!optionalLocalPlayer) {
return false;
}
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
__weak GKLocalPlayer *localPlayer = [[optionalLocalPlayer class] localPlayer];
return localPlayer.isAuthenticated;
}

Expand Down