我正在尝试将GameCenter
Authentication View Controller 延迟2秒,然后再显示。我的VC中大约有2秒钟的按钮动画,我不希望它们被GameCenter
Authentication View Controller 的显示所阻塞。有什么建议吗?
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)
}
答案 0 :(得分:2)
也许,好的旧版大型中央调度(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()
}
}