【发布时间】: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