我正在尝试将 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)")
}
}
}
}
}