GameCenter login alert

后端 未结 7 1330
无人共我
无人共我 2021-02-02 01:59

In a game I am developing using GameCenter, I want to handle the following scenario:

  1. the user starts up the game. He is shown the system alert that prompts him to
相关标签:
7条回答
  • 2021-02-02 02:28

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

    0 讨论(0)
提交回复
热议问题