ios - 验证玩家时无成员 'presentViewController'

标签 ios swift game-center

我正在尝试登录 GameCenter 我的应用程序。我收到错误:

Value of type 'GameScene' has no member 'presentViewController' when trying to present the view controller.

我的认证功能

func authPlayer(){
    let localPlayer = GKLocalPlayer.localPlayer()

    localPlayer.authenticateHandler = {
        (view, error) in

        if view != nil {
            self.presentViewController(view!, animated: true, completion: nil)
        }
        else {
            print(GKLocalPlayer.localPlayer().authenticated)
        }
    }
}

最佳答案

self.presentViewController 仅当 self 是 UIViewController 的子类时才有效。

此外,如果 view 是 UIView 而不是 UIViewController,则:

self.presentViewController(view!, animated: true, completion: nil)

也不会工作,除非 view 命名不当并且实际上是 UIViewController 子类。这不是 GameKit 特有的。 iOS UI 层次结构的基础知识是:

App -> Key Window -> Root View Controller -> Child View Controller -> Root View

您可以有许多 subview Controller ,但每个 View Controller 只有一个 subview Controller 。每个 UIViewController 都有一个或多个 UIView,并且这些 View 可以有一个或多个 subview ,具体取决于其类型和性质。

关于ios - 验证玩家时无成员 'presentViewController',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36985913/

相关文章:

swift - 从变量分配 UIButton 目标

swift - 如何让一个 SKSpriteNode 跟随另一个 SKSpriteNode

iphone - iOS 开发 : After updating my iPhone 4 to iOS 4. 3 Beta 3,我的应用程序显示 "This game is not recognized by Game Center"

ios - 无法在 Swift 4 中将 UILabel 添加到 UIView

ios - 不再能够通过 oauth : "the page requested was not found" 登录 iOS 应用程序

iOS 使用 Plist 中的数据填充 UITableView

ios - 游戏中心。获取真实姓名

ios - 来自 UIImage 或来自文件的 vImage - Swift 和 Accelerate 框架

ios - 如何从 firebase firestore 获取时间戳日期?

ios - 游戏中心整合与程序设计