【问题标题】:How do I get the current user's name from Game Center如何从游戏中心获取当前用户名
【发布时间】:2016-05-29 00:09:44
【问题描述】:

当经过身份验证的处理程序在从 Game Center 返回时触发时,本地玩家会以 displayName = "Me" 列出,别名是玩家的用户名。但是我想显示用户的全名,所以想要实际的 displayName,而不是“我”。

有没有办法指定我想要全名,而不是“我”?

【问题讨论】:

    标签: ios game-center


    【解决方案1】:

    我更喜欢显示别名,尤其是在与随机玩家匹配时,但别名和 displayName 都要求玩家的身份验证完成才能开始返回其适当的值。

    为了启动身份验证过程,您必须设置本地播放器的身份验证处理程序。只需设置它即可启动该过程,并且该方法将在几秒钟内被调用。之后本地玩家的别名和显示名应该是正确的。

    例如:

     class YourGameCenterManager:GKGameCenterControllerDelegate,
                        GKLocalPlayerListener
     {
       var localGCAccount: GKLocalPlayer!
       var active               = false
    
       init()
       { 
         localGCAccount     = GKLocalPlayer.localPlayer()
         localGCAccount?.authenticateHandler = gameCenterAuthentication
       }
    
       func gameCenterAuthentication(gameCenterVC :UIViewController?, err:NSError?)
       {    
          if gameCenterVC != nil
          {       
            // Game center wants to display a sign-on view ...
            // note: I personally never got this to actually happen
          }
          else if localGCAccount?.authenticated ?? false
          {
             if not(active)
             {
               active = true
               localGCAccount?.unregisterAllListeners()
               localGCAccount?.registerListener(self) 
    
               // ... whatever else you need to do when Game Center is ready
               // at this point localGCAccount's alias and displayName should be ok
             }
          }
          else if active
          {   
            //... Game Center just went bad ... do what you have to to to handle it    
            active = false      
          }         
       }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-10
      • 2018-02-11
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      相关资源
      最近更新 更多