用户更改时的GameKit通知

时间:2010-09-20 08:33:55

标签: iphone gamekit

我对游戏套件有一些问题。 一切正常,olny问题是用户登录的变化。 我想知道用户何时在我的应用运行时注销或更改游戏中心中的帐户。 我已经使用下一个代码进行此类通知,但它不起作用

 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

[nc addObserver: self selector:@selector(authenticationChanged) name:GKPlayerAuthenticationDidChangeNotificationName object:nil];

我没有收到任何通知,这个cose在视图中加载了!

任何想法? 请帮助我!!

我尝试创建一个新项目,只有whit gamecenter登录并通知但问题没有解决:(

- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(authenticationChanged) name:GKPlayerAuthenticationDidChangeNotificationName object:nil];
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)        {NSLog(@"SDADA  %@",error);}];
NSLog(@"%@",[[GKLocalPlayer localPlayer]alias]);
 }


  -(void)authenticationChanged

   {

NSLog(@"ooo");

    }

我忘记了什么?

3 个答案:

答案 0 :(得分:2)

在iOS 4.1下,GKPlayerAuthenticationDidChangeNotificationName不会在模拟器下的后台触发。我向Apple报告这是一个错误,他们回复说这个通知会在iOS 4.2恢复时触发。

答案 1 :(得分:0)

代码似乎是正确的。还要检查您的处理程序是否类似于:

- (void) authenticationChanged
{
    if ([GKLocalPlayer localPlayer].isAuthenticated)
        // Insert code here to handle a successful authentication.
    else
        // Insert code here to clean up any outstanding Game Center-related classes.
}

此外,您可能希望在init函数中注册通知,而不是在viewDidLoad

中注册

答案 2 :(得分:0)

好的,现在我知道我的问题,但我没有解决方案。 问题是该字段是GKLocalPlayer的认证,当用户注销此字段时不会更改。 有些事我会忘记吗? 任何想法??

||||||问题是装置全部工作的模拟器!