【问题标题】:Game Center unauthenticated, request authentication in iOS 12Game Center 未经身份验证,在 iOS 12 中请求身份验证
【发布时间】:2019-01-04 23:48:47
【问题描述】:

Swift 4,iOS 12。

使用 Game Center 记录游戏中的高分。一切正常,假设用户登录到游戏中心。我可以检测到他们什么时候没有,但如果是这种情况,我不能完全弄清楚如何打开 Game Center。

func ask4GameCenter() {
    let myAlert: UIAlertController = UIAlertController(title: "Attention", message: "Log into Game Center to record High Scores", preferredStyle: .alert)

    myAlert.addAction(UIAlertAction(title: "Ignore", style: .default, handler: { (action) in
        self.gameOn()
    }))
    myAlert.addAction(UIAlertAction(title: "Logon", style: .default, handler: { (action) in
        UIApplication.shared.open(NSURL(string: "gamecenter:")! as URL, options: [:], completionHandler: { (success) in
            if success {
                self.gameOn()
            }
        })
    }))
    self.view?.window?.rootViewController?.present(myAlert, animated: true, completion: nil)
}

【问题讨论】:

    标签: ios swift game-center


    【解决方案1】:

    好的,我找到了答案。

    func ask4GameCenter() {
        let myAlert: UIAlertController = UIAlertController(title: "Attention", message: "Log into Game Center to record High Scores", preferredStyle: .alert)
    
        myAlert.addAction(UIAlertAction(title: "Ignore", style: .default, handler: { (action) in
            self.gameOn()
        }))
        myAlert.addAction(UIAlertAction(title: "Logon", style: .default, handler: { (action) in
            guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
                return
            }
            UIApplication.shared.open(settingsUrl, options: [:], completionHandler: { (success) in
                if success {
                    self.gameOn()
                }
            })
        }))
        self.view?.window?.rootViewController?.present(myAlert, animated: true, completion: nil)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      • 2013-10-09
      • 2019-06-14
      • 2018-10-19
      • 2015-10-12
      相关资源
      最近更新 更多