我正在学习如何将Gamecenter放入应用程序,使用Xcode,Swift和SpriteKit。每当我玩iOS模拟器时,都不会弹出任何内容(要么弹出"登录"屏幕应该弹出,或者#34;欢迎回来"屏幕应该弹出)并且控制台打印& #34;假&#34 ;.我一直想弄清楚它为什么不起作用。 (哦,如果这有帮助,我现在正在为El Capitan运行OS X Beta)有人请帮忙!
以下是代码:
import GameKit
类ViewController:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
authenticateLocalPlayer()
// Do any additional setup after loading the view, typically from a nib.
}
func authenticateLocalPlayer(){
var localPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {(viewController, error) -> Void in
if (viewController != nil) {
//These 2 lines are the only parts that have been changed
let vc: UIViewController = self.view!.window!.rootViewController!
vc.presentViewController(viewController, animated: true, completion: nil)
}
else {
println((GKLocalPlayer.localPlayer().authenticated))
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}