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

问题描述 投票:0回答:1

我想让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)
}
authentication game-center viewdidload swift4.2
1个回答
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()
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.