我想让GameCenter
身份验证视图控制器在呈现之前延迟2秒。在我的VC中有大约2秒的按钮动画,我不希望它们被GameCenter
认证视图控制器的显示阻止。有什么建议?
override func viewDidLoad() {
super.viewDidLoad()
// Game Center - Authentication of player
NotificationCenter.default.addObserver(self, selector: #selector(showAuthenticationViewController), name: NSNotification.Name(GameKitHelper.PresentAuthenticationViewController), object: nil)
GameKitHelper.sharedInstance.authenticateLocalPlayer()
}
// Game Center - Presents authentication view controller
@objc func showAuthenticationViewController() {
let gameKitHelper = GameKitHelper.sharedInstance
if let authenticationViewController =
gameKitHelper.authenticationViewController {
self.present(authenticationViewController, animated: true, completion: nil)
}
}
// add this to deregister for notifications when the object is deallocated
deinit {
NotificationCenter.default.removeObserver(self)
}
也许,好的旧中央调度(GCD)将完成工作。 2.0是2秒,但无论你需要多长时间都要改变它。
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
// Game Center - Authentication of player
NotificationCenter.default.addObserver(self, selector: #selector(self.showAuthenticationViewController), name: NSNotification.Name(GameKitHelper.PresentAuthenticationViewController), object: nil)
GameKitHelper.sharedInstance.authenticateLocalPlayer()
}
}