gpt4 book ai didi

iphone - 通过 GameKit 登录 iPhone 应用程序

转载 作者:行者123 更新时间:2023-12-03 21:02:35 25 4
gpt4 key购买 nike

我想通过 GameCenter Login API 登录我的应用。

这可能吗?

Apple游戏中心登录API是否公开?

最佳答案

如果您使用的是 iOS 6,请参阅 GKLocalPlayer 的文档。您将看到您将一个 block 分配给 localPlayer 的“authenticateHandler”属性。当您分配它时,如果玩家尚未登录到 Game Center,则该 block 的参数之一 (UIViewController *viewController) 将填充 View Controller 的地址,该 View Controller 将显示常规的 Apple Game Center 登录屏幕。获得该地址后,您将呈现ViewController:viewController,然后用户将看到正常的Apple登录屏幕。当用户完成与其交互时,您会收到“gameCenterViewControllerDidFinish”的回调。您提供的 block 运行多次,这使得该过程很难遵循,但它确实有效。对于它的值(value),我将在下面发布我正在使用的似乎有效的方法。它假定 iOS5 或 iOS6。它对于 5 之前的任何版本都没有好处。OS6 是在 iOS6 上返回 YES 的方法,否则返回 NO。本文不是为公众使用而编写的,因此请原谅其中的所有调试内容和无法解释的内容。

-(void) authenticateLocalPlayer {
ANNOUNCE
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
_lastError = nil;

//iOS 6
if ( [self os6] ) {
localPlayer.authenticateHandler = ^(UIViewController *loginVC, NSError *error) {
NSLog(@"in authenticateHandler 1");
[self setLastError:error];
//... resume application responses
[[CCDirector sharedDirector] resume]; //if not paused does nothing
if ( [GKLocalPlayer localPlayer].authenticated) {
NSLog(@"in authenticateHandler 2 - local player is authenticated");
} else if (loginVC) {
NSLog(@"in authenticateHandler 3 - local player is not authenticated, will present VC");
//... pause applications responses
[[CCDirector sharedDirector] pause];
[self presentViewController:loginVC];
} else {
NSLog(@"in authenticateHandler 4 - local player is NOT authenticated, no VC returned");
}
NSLog(@"authenticateHandler error: %@", error.localizedDescription);
};

//iOS 5
} else {
if ( [GKLocalPlayer localPlayer].authenticated == NO ) {
//no completion handler because we're relying on NSNotificationCenter
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];
NSLog(@"local player authentication requested");
} else {
NSLog(@"local player was already authenticated");
}
}

}

关于iphone - 通过 GameKit 登录 iPhone 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13511030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com