ios - GameKit 无法在 watchOS 3 上运行

标签 ios swift gamekit watchos-3

我正在尝试将 GameKit 支持添加到我的 watchOS 应用程序中。但是,在设备上运行应用程序时,身份验证失败,并出现错误 NSURLErrorDomain code -1009 (null)。在模拟器中运行时,应用程序无法构建,并提示找不到 GameKit 模块。

如何修复这些错误?我使用的是 Xcode 8 + watchOS 3 和 iOS 10。

编辑:GameKit 身份验证帮助程序类的代码

import Foundation
import GameKit //ERROR: Can't find module when running in simulator
import WatchKit

let singleton = GameKitHelper()

class GameKitHelper {
    var gameCenterEnabled = false
    var points: Int64? = 0
    var rankings: [GKScore] = []
    let leaderboard = "LEAD_ID"
    var leaderboardRequest: GKLeaderboard?

    class var sharedInstance: GameKitHelper {
        return singleton
    }

    func authenticateLocalPlayer() {
        let player = GKLocalPlayer.localPlayer()
        print("Authenticating local player")
        player.authenticateHandler = { error in
            if player.isAuthenticated {

                self.gameCenterEnabled = true
                DispatchQueue.main.async { () -> Void in
                    WKInterfaceController.reloadRootControllers(withNames: ["View"], contexts: nil)
                }  
            } 
            else {
                self.gameCenterEnabled = false
                if error != nil {
                    print("GK Auth Error: \(error.debugDescription)")
                }
            }
        }
    }
}

最佳答案

看起来它可以与 WatchOS4 配合使用,但不能立即使用:

  • 看来您必须创建一个具有自己的 GameCenter 排行榜的单独应用,然后您可以使用 GC 组与 iOS 伴侣共享相同的数据。

关于ios - GameKit 无法在 watchOS 3 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39857703/

相关文章:

ios - 游戏中心登录问题

ios - 以 float 大小绘制 UIImage

swift - Swift 中的百分比评级栏

ios - GKScore 必须包含一个初始化值?

ios - 使用GameKit通过不同的帐户将数据保存到iCloud

ios - 无法在 ObjC 中访问 Swift ViewModel 属性

ios - 无法编辑/删除 uitableview 中的顶行 - Swift

ios - tableView 滚动真的很慢——我调用了太多方法?

iphone - 在 ios 5.0 中显示带有 Textfield 的警报 View 时键盘无法打开

xcode - 我如何在 Swift SpriteKit 的游戏中保存 "coins"?