8

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 app.

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

marzapower
  • 5,531
  • 7
  • 38
  • 76
Idan
  • 5,717
  • 10
  • 47
  • 84

2 Answers2

4

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.");
        } 
    };
  • Work like a charm. Just do not forget to enable Game Centre from itunesconnect otherwise you will receive error no matter user is logged in GC or not. – hris.to Jul 04 '14 at 12:11
0

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?

marzapower
  • 5,531
  • 7
  • 38
  • 76
  • You understood my question wrong. I was asking if it's possible to know if the user is currently logged-in to GC using another app (third-party of apple's one), without actually presenting the alert view asking him to connect, in case he wasn't actually connected. For example, an imaginary scenario would be the user is already connected to GC , and if so i'd use it, otherwise I'd like to default to Open Feint, without using GC at all (and accordingly, not asking the user to log-in to it) . Clear now ? – Idan Jun 08 '11 at 14:53
  • I understood your question. What I am saying is that connection to Game Center is limited to each single app, so you cannot share GC connection between apps. Each app has to connect, relying on the default SDK methods (and alerts, of course). – marzapower Jun 08 '11 at 14:56
  • Well, You do share connection between apps, that's the all point... you log-in once and then you're already connected across all other apps. However, I guess you're right since I didn't find any other indication that it's possible, it seems like you have to run the authenticate function to actually refresh the GC data per application. – Idan Jun 08 '11 at 15:01
  • You do not share connection. Simply, if you are using a valid App Store account or if you already used the login popup in another app the new one do not ask you for your credentials. Each app inside makes a call to the standard SDK login methods, but iOS knows that you can log into your GC account so it does not bother you. But every app rely on the default SDK methods. And every app make a connection in background to the GC, they do not share the same connection. Simply iOS will try not to bother you if not necessary. – marzapower Jun 08 '11 at 15:08
  • Why doesn't it ask you for your credentials ? Because it knows you're already connected to GC using other app after the authentication. By saying "the same connection" I wasn't implying it's the same socket, even tho it may be, I meant it suffice to log-in only once. Anyway, it's doesn't really matter, cause what I wanted to achieve was impossible. Thanks :) – Idan Jun 08 '11 at 15:17
  • When you reboot the device and use a GC-powered app it does not ask you for credentials too. Why? Did you think about that? Is because iOS is saving you time. – marzapower Jun 08 '11 at 15:18
  • There's no way this is impossible, because "Army of Darkness: Defense" works in exactly this way. It never prompts me to log in to GC, but if I have logged into GC in another app, it detects that status and enables GC functionality. There must be a way... will try to remember to post back here when I find it. :) – IQpierce Aug 03 '11 at 23:49