延迟 GameCenter 身份验证视图控制器的显示 - Swift 4.2

Delay GameCenter Authentication View Controller from being presentation - Swift 4.2

我正在尝试让 GameCenter A​​uthentication View Controller 在显示之前延迟 2 秒。在我的 VC 中有大约 2 秒的按钮动画,我不希望它们被 GameCenter A​​uthentication View Controller[=18= 的呈现所阻止].有什么建议吗?

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)
}

也许,老好人 Grand Central Dispatch (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()
    }
}