简体   繁体   中英

Game Center authentication can take a very long time. How to work around it?

Waiting for Game Center authentication to complete is a bad idea since it can take a very long time. Moreover, authentication is done not just at game launch but whenever you switch back to a game via fast app switching.

But not waiting for authentication presents problems:

  • how do you resume a saved game if you don't know who the player is? Ideally, a saved game would be associated with who was playing so you don't have someone resuming another person's game.

  • how do you resume a game after an app switch back if you don't know who the player is (the player may have changed via the Game Center app)?

  • a Game Center log in alert might pop up in the middle of an action game (it is not paused)

  • what if the game is over before authentication completes? What if the initial authentication completes after a few games have been played? What if the initial authentication completes after an app switch or two (which in turn result in more authentications)?

What is a reasonable approach to handle these problems?

Hmm.. i only authenticate at the start of app.. Its set by yourself when you want to authenticate the player.. You might want to save the player alias when the player is first authenticated.. Means:

sharedData.myName =  [[GKLocalPlayer localPlayer]alias];

So when the player app switch and stuff, but is not authenticated, you save data under this player alias.. So when the player is finally authenticated, you send the data to GameCenter

Meaning in your checking GameCenter part..

if(!inGame)
{
  [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error){
        if(error == nil){
  if(sharedData.myName ==nil)
  {
    sharedData.myName = [[GKLocalPlayer localPlayer]alias];
  }
  else if([[GKLocalPlayer localPlayer]alias] == sharedData.myName)
  {
    [self sendSavedData];
  }
  else if([[GKLocalPlayer localPlayer]alias] != sharedData.myName)
  {
    // create new data or look for other saved data which has the same name..
    // set sharedData.myName to current player Name..
  }
}

enter code here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM