I want to be able to know if the user running my app is connected to GameCenter (through GameCenter app or through other app), when i'm first running my ap开发者_如何学JAVAp.
I found out that if I check the boolean:
[GKLocalPlayer localPlayer].authenticated)
it returns false. I guess one thing that might fix this is running at startup this:
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
However, in case the user is not connected this brings the game center pop up which requests an existing account or creating a new one.
So my question is: is there a way to know my user connected GC outside of my app while my app was down, without popping up the above alert in case he is not connected ?
Thanks!!
You can do it on iOS 6.0 or higher:
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController == nil && error == nil) {
NSLog(@"Here, you know that the user has already signed to Game Center, whether in through your app or not.");
}
};
It seems to me that Game Center authenticates the user within each different application and not globally through iOS. So, you cannot check the authentication status of the user without using the authenticateWithCompletionHandler:
method.
By the way, I think that you should revise this User Interface mechanism. It will bring you to a couple of problems. Game Center authentication will use a global account (first of all the App Store account) shared amongst all apps, and you should rely on Game Center to handle authentication. Supposing that you can do what you are looking for (and I think that's not possible), if you are already logged in through a 3rd party app, you will be able to log to GC even in yours; but if you are not logged in outside your app, you will not be able to use GC in your app.
This could be a problem for you because if the user has a valid account, and he currently has logged out of the App Store from the Settings app, he will not be able to log into GC for your app (since you do not want to show the user the log in alert). You will have to rely on 3rd party apps to enable all the GC features. So, GC will become useless, at this point.
Is this really what you want from your app? Why enabling GC if the user will probably be not able to use it efficiently?
精彩评论