authenticate the player using GameKit

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

// Override point for customization after application launch.

let LocalPlayer = GKLocalPlayer()

LocalPlayer.authenticateHandler = // How To Do This ??

return true

}


Please Help Me With This.

Replies

This worked for me....


GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
    localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
        if (viewController != nil)GCViewController=viewController;
        if([[GKLocalPlayer localPlayer] isAuthenticated]){
            GKGameCenterViewController *aLeaderboardController = [[GKGameCenterViewController alloc] init];
            if (aLeaderboardController != nil){
                 aLeaderboardController.gameCenterDelegate = self;
                 aLeaderboardController.viewState=GKGameCenterViewControllerStateLeaderboards;
                 [self presentViewController:aLeaderboardController animated:YES completion:nil];
            }
        }else if(GCViewController){
            [self presentViewController:GCViewController animated:YES completion:nil];
            GCViewController=nil;
        }else{
           UIAlertController *alert =
               [UIAlertController alertControllerWithTitle:@"Not signed-in to Game Center" message:@"You must be signed-in to Game Center to ........\nOpen the Game Center App and Sign In or Create New Account.\nThen........." preferredStyle:UIAlertControllerStyleAlert];
               [alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
               }]];
              [self presentViewController:alert animated:YES completion:nil];
        }
    };