tags:

views:

251

answers:

3

Hi there, 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??

A: 

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

dkk
the method work if the application is not in background,the method authenticationChanged is calling when the application call authenticateWithCompletionHandler:^(NSError *error) {}
digitalPad
the problem is when the application is in background and in GameCenter the user signout or change account, in this case when the app resume from background i've not notification!
digitalPad
is it possible that the problem is the simulator?
digitalPad
the GameKit reference sais: "In iOS 4 and later, multitasking allows multiple applications to run on the device simultaneously. When your game moves into the background, the player may log out of their Game Center account. Another player may have logged in. The local player may not stay authenticated even while your application is running. For this reason, all Game Center applications must register a notification handler so that they can be informed when the local player disconnects from Game Center." so.. it should work (as long as you are using iOS 4 or later).
dkk
I know what GameKit references sais but it doesn't work :(
digitalPad
anyway tnx a lot!
digitalPad
A: 

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!

digitalPad
You should be using the readonly property authenticated instead of isAuthenticated. Maybe this is causing some kind of problem.
dkk
also authenticated property is always "YES", i dont'know but i does not receive GKPlayerAuthenticationDidChangeNotificationName when my user log out.
digitalPad
and my GKLocalPlayer do not change , there are some methot for release GKLocalPlayer ore for delete it'
digitalPad
Ok now i know that the problem is the simulator, with device all work ;)
digitalPad