1

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??

3 Answers 3

2

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

0

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

4
  • the method work if the application is not in background,the method authenticationChanged is calling when the application call authenticateWithCompletionHandler:^(NSError *error) {} Sep 20, 2010 at 9:33
  • 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! Sep 20, 2010 at 9:34
  • is it possible that the problem is the simulator? Sep 20, 2010 at 9:34
  • 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).
    – Daniel
    Sep 20, 2010 at 10:31
0

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!

4
  • You should be using the readonly property authenticated instead of isAuthenticated. Maybe this is causing some kind of problem.
    – Daniel
    Sep 21, 2010 at 8:33
  • also authenticated property is always "YES", i dont'know but i does not receive GKPlayerAuthenticationDidChangeNotificationName when my user log out. Sep 21, 2010 at 9:00
  • and my GKLocalPlayer do not change , there are some methot for release GKLocalPlayer ore for delete it' Sep 21, 2010 at 9:02
  • Ok now i know that the problem is the simulator, with device all work ;) Oct 1, 2010 at 9:45

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.