GameCenter login alert

烈酒焚心 提交于 2019-12-02 19:36:36

The behavior is something to the effect of, after N unsuccessful attempts - disable GameCenter for the app. Restarting the app or going to login in gamecenter itself will get it back online.

I forget which doc I read this in, but there is an Apple doc out there that explains this behavior.

Here's an is an idea to workaround this issue:

No matter if a "GC authenticateWithCompletionHandler"-Request is cancelled

  • by the user tapping "Cancel" in the dialog

or due to the fact that

  • GC is disabled on the device (which happens after the user has cancelled the alert-dialog exactly 3 times (in iOS 5 at least))

you will always receive an NSError with code 2 saying "The requested operation has been cancelled.".

The only differentiator that i could find is the time passed between the authenticateWithCompletionHandler-Request and the the execution of the completion-Handler.

So when sending the request i am saving the time:

requestTime = [NSDate date]; 

and in my completion handler i measure the time lapsed:

NSDate* now = [NSDate date];
CFTimeInterval elapsedTimeSinceAuthenticationRequest = [now timeIntervalSinceDate:requestTime];
NSLog(@"time Elapsed: %f", elapsedTimeSinceAuthenticationRequest);

If the user cancelled the request, the time passed will be significantly longer compared to the time passed if GC cancelled the operation. In my tests, it took a user at least one second to cancel the dialog, whereas a GC-cancelled request took less than 0.1 seconds (on my iPhone 4)

Of course, these values may vary depending on the device the code runs on and on what else the processor is busy with at the moment. One pitfall i already examined is the application launch: If you are sending the authenticationRequest during applicationDidFinishLaunching as suggested by Apple, it took much longer for GC to cancel the request in my case, because the device is busy loading views and whatever is necessary to launch the app.

So let me know if you tried this solution and if it worked for you, as will i once i have done further testing...

I couldn't find a good answer for this either, so I decided to just replicate the message once the I start getting the cancel error. This is still in development but it basically changes the button callback to display the error alert rather than display the leader-board.

Just a note, not sure if this will be approved or not since I am replicating an Apple error message.

-(void) gcLogin: (id) sender {
    [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
        if(error) {
            if([[error domain] isEqualToString:GKErrorDomain] && [error code] == GKErrorCancelled) {
                [ResourceManager showAlertWithTitle:@"GameCenter Disabled" message:@"Sign in with Game Center application to enable"];
                mGameCenterCancelled = YES;
            }
            NSLog(@"%@", [error description]);
        } else { 
            [self updateMenu];
            mGameCenterCancelled = NO;
        }
    }];
}

I am playing around with Game Center myself right now I have seen the very same behavior. There is nothing in the documentation saying anything about the dialog only showing up the first couple of times. In my case I would like a way to tell beforehand if the user is already logged into Game Center, so that I can behave appropriately. But now I can not know this before the dialog is shown to the user.

Since we are running in the sandbox during development this behavior might of course be something that behaves differently during production but this is not an easy thing to find out.

May be the link will helpful (First three paragraphs): http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/Users/Users.html#//apple_ref/doc/uid/TP40008304-CH8-SW9

The main point is in a rectangle "Important".

marcwjj

I'm facing the same issue. Though I couldn't find a way to enforce poping up the same dialog for logging into Game Center, I did find a way to implement a warning message saying 'gamecenter is disabled' when user clicks on a leaderboard icon:

if([GKLocalPlayer localPlayer].authenticated == NO)
{
// Prompt a warning message alert saying game center is disabled
}
else
{
// Proceed with opening leaderboard
}

Hope this helps!

It appear that iOS will disable Game Center completely and prevent it from prompting after the user chooses to Disable Game Center (the option would appear on your fifth 5th Game Center cancel sign in).

To restore the device to the original state where the login prompt will appear again. Simply sign in using the Game Center app using a normal working Game Center account (non Tester). Once you are in, Sign Out. It should start prompting you again on within your app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!