开发者

GameKit Notification when user change

i've some problem with game kit. All work fine, the olny problem is the changement of user logged. I want to know when the user signout or change account in gamecenter when my app is running. I've use the next code for this kind of notification but it don't work

 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

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

I do not receive any notification, this cose in into view did load!

Any ideas?? Please Help ME!!

I've tryed to create a new project only 开发者_开发知识库whit gamecenter sign in and notification but the problem it's not solved :(

- (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");

    }

what i forgot??


Under iOS 4.1 GKPlayerAuthenticationDidChangeNotificationName does not fire in the background under the simulator. I reported this as a bug to Apple and they replied that this notification will fire upon resume in iOS 4.2


The code seems to be right. Also check that your handler is similar to:

- (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.
}

Also, you probably want to register for notification in the init function and not in viewDidLoad


OK, now i know my problem but i've not the solution. The problem is the field isAuthenticated of GKLocalPlayer, when the user logout this field do not change. are There somethings i forget? any ideas??

||||||THE PROBLEM IS THE SIMULTOR WITH DEVICE ALL WORK!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜