Pause on Game Center Notifications

Forums Programming high score, social and ads networks Pause on Game Center Notifications

This topic contains 8 replies, has 2 voices, and was last updated by  Joshua Goossen 2 years, 11 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
Author Posts
Author Posts
March 26, 2011 at 12:20 pm #229795

alter3cho
Participant
@alter3cho

Hello,

How should i pause a game when game center displays some notification?

example:- In mid game, if i ( press home button -> go to game center -> log out of current account -> get back into the game again using the home button) a notification pops to create or use an existing account.

I tried using [[CCDirector sharedDirector] pause] in the authenticateLocalPlayer method, right before calling authenticateWithCompletionHandler method, but doesn’t seem to work.

Here’s my code:

-(void) authenticateLocalPlayer
{
GKLocalPlayer* localplayer = [GKLocalPlayer localPlayer];
if (localplayer.authenticated == NO)
{
[[CCDirector sharedDirector] pause];
[localplayer authenticateWithCompletionHandler:^(NSError* error)
{
lasterror = error;
[[CCDirector sharedDirector] resume];
}];
}
}

Is there anyway to know if any notification (or anything) pops up?

March 27, 2011 at 1:11 pm #322463

alter3cho
Participant
@alter3cho

Sorry for double post, But It seems

if (localplayer.authenticated == NO)
{
........
}

is run even when the user has logged out using the game center and gets back into the game. It seem to be returning a false positive.

It would be really helpful if someone pointed out how to handle game center in these kind of situations.

May 10, 2011 at 6:08 pm #322464

Joshua Goossen
@goose

Did you find the answer to this. I can’t figure this one out either…

May 10, 2011 at 6:29 pm #322465

alter3cho
Participant
@alter3cho

I did find a way but not sure if it is right. I used The NSNotificationCenter class to notify me of any particular notification. I set the authenticate player metho to post a notification in case of any errors.

May 11, 2011 at 1:42 pm #322466

Joshua Goossen
@goose

How so?

The only GK related notification I found documented is GKPlayerAuthenticationDidChangeNotificationName and for me this gets called much to often.

The only time I would want to pause my game is when someone does as you mentioned earlier and “a notification pops to create or use an existing account”

GKPlayerAuthenticationDidChangeNotificationName gets posted when this happens, but it also get posted one I leave the app, then return to it while still signed into the same GameCenter account. So if I pause my game whenever this notification is posted I will be pausing it at times when there is no reason to pause it.

May 11, 2011 at 6:14 pm #322467

alter3cho
Participant
@alter3cho

I used NSNotificationCenter to post a notification incase any errors occur (Inside the authenticateWithCompletionHandler block Object). Then used the NSNotificationCenter again to set my GameScene as the observer to the posted notification and performed necessary actions.

May 13, 2011 at 6:50 pm #322468

Joshua Goossen
@goose

I got it to pause when I wanted to by using GKPlayerAuthenticationDidChangeNotificationName and setting a check in the authenticateWithCompletionHandler block Object like you did.

But it still doesn’t pause when I am offline and the “Could not connect to Game Center server” notification pops up. I just can’t find any way to retrieve from GameKit when that is going to pop up. It doesn’t send an error in the authenticateWithCompletionHandler like I think it should.

May 14, 2011 at 10:10 am #322469

alter3cho
Participant
@alter3cho

In your GameScene class, add:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pause) name:UIWindowDidResignKeyNotification object:nil];

And:

-(void) pause
{
[[CCDirector sharedDirector] pause];
}

Also in your dealloc method:

[[NSNotificationCenter defaultCenter] removeObserver:self];

To resume, you can resume using CCDirector if the authenticateWithCompletionHandler block returns no errors.

May 15, 2011 at 2:03 am #322470

Joshua Goossen
@goose

Awesome!

That’s exactly what I was missing

thank you.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.