Swift 无法使用watchOS上的GameKit(游戏中心)对本地玩家进行身份验证

Swift 无法使用watchOS上的GameKit(游戏中心)对本地玩家进行身份验证,swift,apple-watch,game-center,gamekit,watchos,Swift,Apple Watch,Game Center,Gamekit,Watchos,我正在尝试将Game Center集成到watchOS应用程序中,但无法验证本地玩家的身份 也许我错过了让watchOS应用程序像iOS应用程序一样访问游戏中心的任何步骤 安装程序 iOS应用程序为iOS 14部署目标 支持在不安装iOS应用程序的情况下运行的配套watchOS应用程序,目标为watchOS 7 游戏中心功能在iOS和watchOS应用程序扩展目标上都处于活动状态 该应用尚未上线,但已在app Store Connect的“准备提交”中 游戏中心复选框处于启用状态,在应用商店连

我正在尝试将Game Center集成到watchOS应用程序中,但无法验证本地玩家的身份

也许我错过了让watchOS应用程序像iOS应用程序一样访问游戏中心的任何步骤

安装程序
  • iOS应用程序为iOS 14部署目标
  • 支持在不安装iOS应用程序的情况下运行的配套watchOS应用程序,目标为watchOS 7
  • 游戏中心功能在iOS和watchOS应用程序扩展目标上都处于活动状态
  • 该应用尚未上线,但已在app Store Connect的“准备提交”中
  • 游戏中心复选框处于启用状态,在应用商店连接上
  • App Store Connect上已经创建了一些排行榜
  • iOS应用程序能够连接到游戏中心进行身份验证、提交分数和显示排行榜
  • 在模拟器上测试时,我有一个iPhone和一块手表。沙盒帐户在iPhone上经过身份验证
  • 当在真实设备上测试时,我有一个iPhone和一块手表,真实帐户在iPhone上经过身份验证
已经试过了 在watchOS应用程序扩展上,我正在呼叫:

GKLocalPlayer.local.authenticateHandler={中出现错误
}
这与在iOS上进行身份验证的方法非常相似,在iOS上也可以,甚至在模拟器上也可以


调用该方法并在模拟器上运行时,我在Xcode的调试区域中得到以下日志:

[Error] _authenticateUsingAlert:Failed to authenticate player with existing credentials.Error: Error Domain=GKErrorDomain Code=6 "The requested operation could not be completed because local player has not been authenticated." UserInfo={NSLocalizedDescription=The requested operation could not be completed because local player has not been authenticated.}
在完成处理程序上接收到的错误消息为:

Error Domain=GKErrorDomain Code=3 "The requested operation could not be completed due to an error communicating with the server." UserInfo={NSLocalizedDescription=The requested operation could not be completed due to an error communicating with the server.}
Error Domain=GKErrorDomain Code=15 "The requested operation could not be completed because this application is not recognised by Game Center." UserInfo={NSLocalizedDescription=The requested operation could not be completed because this application is not recognised by Game Center.}

在真实设备上测试相同场景时,我会得到以下日志:

[Error] _authenticateUsingAlert:Failed to authenticate player with existing credentials.Error: Error Domain=GKErrorDomain Code=15 "The requested operation could not be completed because this application is not recognised by Game Center." UserInfo={GKServerStatusCode=5019, NSUnderlyingError=0x11e3a6c0 {Error Domain=GKServerErrorDomain Code=5019 "status = 5019, no game matching descriptor: ios:com.myApp.test.watch.extension::0+-1" UserInfo={GKServerStatusCode=5019, NSLocalizedFailureReason=status = 5019, no game matching descriptor: ios:com.myApp.test.watch.extension::0+-1}}, NSLocalizedDescription=The requested operation could not be completed because this application is not recognised by Game Center.}
完成处理程序的错误为:

Error Domain=GKErrorDomain Code=3 "The requested operation could not be completed due to an error communicating with the server." UserInfo={NSLocalizedDescription=The requested operation could not be completed due to an error communicating with the server.}
Error Domain=GKErrorDomain Code=15 "The requested operation could not be completed because this application is not recognised by Game Center." UserInfo={NSLocalizedDescription=The requested operation could not be completed because this application is not recognised by Game Center.}

这两个错误类似于当应用程序未在app Store Connect上启用Game Center时,您在iOS上收到的消息。如前所述,情况并非如此,因为在iOS上工作正常


我还尝试将该应用程序移动到app Store Connect上的游戏中心组,因为它说这是为了分享排行榜和成就,但结果是一样的。

经过数周的努力,我发现(艰难的方式)游戏中心只有在真正的设备上才能在watchOS上运行,而且效果非常有限

您可以访问本地玩家显示名称,但不能提交分数

我甚至尝试将该应用程序添加到游戏中心群组,但都没有效果

--


另外,它仍然会在Xcode的控制台上显示错误消息和警告,说明用户未通过身份验证,或者游戏中心无法识别应用程序,但如果您尝试在使用
GKLocalPlayer.local.displayName
进行身份验证后获取
GKLocalPlayer.local.authenticateHandler
,它将起作用。它显然也会将分数提交到排行榜,或者至少不会显示错误,但是分数从未被提交。

我有一个类似的错误,但与使用Apple Watch操作系统无关,但是我有这个错误,这是一个简单的疏忽,因为我在app Store connect上添加应用程序时没有输入正确的包标识符,所以如果您有类似的错误,请尝试检查包标识符是否与您的应用程序对应项目。

不幸的是,它与包标识符无关。该应用程序已经上线,iOS应用程序可以按预期与GameKit交互。