我正在尝试为我的watchOS应用添加GameKit支持。但是,在设备上运行应用程序时,身份验证将失败并显示错误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)")
}
}
}
}
}
答案 0 :(得分:0)
看起来它适用于WatchOS4,但不是马上就可以了: