Skip to content

Commit abf72ae

Browse files
authored
Merge pull request #358 from firebase/feature/rc_rest_update
Change GKLocalPlayer to be runtime referenced
2 parents 6181e94 + 005633e commit abf72ae

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

auth/src/ios/credential_ios.mm

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,16 @@ @implementation PhoneListenerDataObjC
166166
FIREBASE_ASSERT(future_api != nullptr);
167167

168168
const auto handle = future_api->SafeAlloc<Credential>(kCredentialFn_GameCenterGetCredential);
169+
/**
170+
Linking GameKit.framework without using it on macOS results in App Store rejection.
171+
Thus we don't link GameKit.framework to our SDK directly. `optionalLocalPlayer` is used for
172+
checking whether the APP that consuming our SDK has linked GameKit.framework. If not, will
173+
complete with kAuthErrorInvalidCredential error.
174+
**/
175+
GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init];
169176

170177
// Early-out if GameKit is not linked
171-
if ([GKLocalPlayer class] == nullptr) {
178+
if (!optionalLocalPlayer) {
172179
future_api->Complete(handle, kAuthErrorInvalidCredential,
173180
"GameCenter authentication is unavailable - missing GameKit capability.");
174181
return MakeFuture(future_api, handle);
@@ -197,11 +204,18 @@ @implementation PhoneListenerDataObjC
197204

198205
// static
199206
bool GameCenterAuthProvider::IsPlayerAuthenticated() {
207+
/**
208+
Linking GameKit.framework without using it on macOS results in App Store rejection.
209+
Thus we don't link GameKit.framework to our SDK directly. `optionalLocalPlayer` is used for
210+
checking whether the APP that consuming our SDK has linked GameKit.framework. If not,
211+
early out.
212+
**/
213+
GKLocalPlayer *_Nullable optionalLocalPlayer = [[NSClassFromString(@"GKLocalPlayer") alloc] init];
200214
// If the GameKit Framework isn't linked - early out.
201-
if ([GKLocalPlayer class] == nullptr) {
215+
if (!optionalLocalPlayer) {
202216
return false;
203217
}
204-
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
218+
__weak GKLocalPlayer *localPlayer = [[optionalLocalPlayer class] localPlayer];
205219
return localPlayer.isAuthenticated;
206220
}
207221

0 commit comments

Comments
 (0)