Skip to content

Commit

Permalink
Use DispatchQueue.main.async
Browse files Browse the repository at this point in the history
  • Loading branch information
Mads Rode committed Aug 26, 2020
1 parent 5776423 commit f775dbc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
16 changes: 9 additions & 7 deletions ios/GameAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ class GameAuth: RCTEventEmitter {

@objc
func initAuth(_ showUIIfUnauthenticated: Bool) {
let ui = UIApplication.shared.keyWindow?.rootViewController;

let player = GKLocalPlayer.local
if(player.authenticateHandler == nil) {
player.authenticateHandler = { vc, error in
player.authenticateHandler = { vc, error in
self.loginUI = vc;
if(vc != nil) {
if(showUIIfUnauthenticated) {
ui?.present(vc!, animated: true, completion: nil);
DispatchQueue.main.async {
UIApplication.shared.keyWindow?.rootViewController?.present(self.loginUI!, animated: true, completion: nil);
}
}
else {
self.sendEvent(withName: self.C_OnAuthenticated, body: ["isAuthenticated":false, "error": error])
self.sendEvent(withName: self.C_OnAuthenticated, body: ["isAuthenticated":false, "error": error?.localizedDescription as Any])
}
}
else {
self.sendEvent(withName: self.C_OnAuthenticated, body: ["isAuthenticated":player.isAuthenticated, "error": error])
self.sendEvent(withName: self.C_OnAuthenticated, body: ["isAuthenticated":player.isAuthenticated, "error": error?.localizedDescription as Any])
}
}
}
Expand All @@ -36,7 +36,9 @@ class GameAuth: RCTEventEmitter {
}
else {
if(showUIIfUnauthenticated && self.loginUI != nil) {
ui?.present(self.loginUI!, animated: true, completion: nil);
DispatchQueue.main.async {
UIApplication.shared.keyWindow?.rootViewController?.present(self.loginUI!, animated: true, completion: nil);
}
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import {
} from 'react-native';

interface Player {
alias: String;
displayName: String;
playerID: String;
alias: string;
displayName: string;
playerID: string;
}

export interface IdentityVerificationSignature {
publicKeyUrl: String;
signature: String;
salt: String;
timestamp: Number;
publicKeyUrl: string;
signature: string;
salt: string;
timestamp: number;
}

type PlayGamesAuthType = {
Expand Down Expand Up @@ -44,7 +44,7 @@ if (PlayGamesAuth) {
PlayGamesAuth.onAuthTokenChanged = (callback: any) => {
return DeviceEventEmitter.addListener(
PlayGamesAuth.AUTH_TOKEN_CHANGED_EVENT,
(token: String) => {
(token: string) => {
callback(token);
}
);
Expand All @@ -64,11 +64,11 @@ if (NativeModules.GameAuth) {

type GameCenterAuthType = {
initAuth(showUIIfUnauthenticated: boolean): void;
isAuthenticated(): Promise<Boolean>;
isAuthenticated(): Promise<boolean>;
getPlayer(): Promise<Player>;
getServerAuth(): Promise<IdentityVerificationSignature>;
onAuthenticate(
callback: (isAuthenticated: boolean) => void
callback: (isAuthenticated: boolean, error?: string) => void
): EmitterSubscription;
};

Expand Down

0 comments on commit f775dbc

Please sign in to comment.