设为首页 加入收藏

TOP

GameCenter authenticate:GKErrorDomain Code=2 "The requested operation has been cancelled."
2014-11-24 02:32:54 】 浏览:1720
Tags:GameCenter authenticate:GKErrorDomain Code " The requested operation has been cancelled."

测试GameCenter的登陆authencitate,登陆方法如下:


[cpp]
-(void) authenticateLocalPlayer {
GKLocalPlayer* localPlayer =
[GKLocalPlayer localPlayer];

localPlayer.authenticateHandler =
^(UIViewController *viewController,
NSError *error) {

[self setLastError:error];

if (CCDirector::sharedDirector()->isPaused()) {
CCDirector::sharedDirector()->resume();
}

// Player already authenticated
if (localPlayer.authenticated) {
_gameCenterFeaturesEnabled = YES;
} else if(viewController) {
CCDirector::sharedDirector()->pause();
[self presentViewController:viewController];
} else {
_gameCenterFeaturesEnabled = NO;
}
};
}

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

localPlayer.authenticateHandler =
^(UIViewController *viewController,
NSError *error) {

[self setLastError:error];

if (CCDirector::sharedDirector()->isPaused()) {
CCDirector::sharedDirector()->resume();
}

// Player already authenticated
if (localPlayer.authenticated) {
_gameCenterFeaturesEnabled = YES;
} else if(viewController) {
CCDirector::sharedDirector()->pause();
[self presentViewController:viewController];
} else {
_gameCenterFeaturesEnabled = NO;
}
};
}

使用GameCenter在模拟器上运行没有问题,在真机上第一次登陆运行就遇到了NSError错误提示:


[cpp]
GKErrorDomain Code=2 "The requested operation has been cancelled."

GKErrorDomain Code=2 "The requested operation has been cancelled."

正常情况下登陆,如果你的Apple ID默认已经登陆过,会弹出欢迎XX界面

第一次登陆,会弹出GameCenter登陆AppleID的提示框

localPlayer.authenticated值为false 表示登陆失败,但是我的AppleID已经登陆过了,正常情况下是不应该失败的


最后在stackoverflow上的一哥们的方法解决了 问题可能是由于登陆函数和模拟器上的函数绑定了。。。原因不太重要,重要的解决办法

在View加载的地方调用一下如下函数:


[cpp]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:"]];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:"]];
把你的APPID登陆进去 然后点log out 再把上面的代码从程序中删除掉

再重新在真机上调试你的程序即可


解决办法参考:stackoverflow


GameCenter登陆需要注意:

1.ios6.0后需要手动设置authenticateHandler,authenticateWithCompletionHandler: 已经在6.0中丢弃不用了

2.authenticationHandler第一个参数viewController在AppleID没有登陆的时候 需要手动显示“登陆GameCenter"界面,还要需要注意暂停逻辑

[cpp]
localPlayer.authenticateHandler =
^(UIViewController *viewController,
NSError *error)

localPlayer.authenticateHandler =
^(UIViewController *viewController,
NSError *error)3.这个登陆block函数在三种情况下会被调用:


当你设置了authenticationHandler并发出了验证玩家的请求。
当app进入foreground(前台)。
在登录时,例如玩家在进入游戏前没有登录,进入时会弹出登录界面,在这个界面中的任何交互都会调用authenticationHandler。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇POJ 1364 King (差分约束) 下一篇BZOJ 1005([HNOI2008]明明的烦恼-..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目