游戏中心比赛总是无效
Game Center match is invalid always
我正在尝试学习如何构建基于游戏中心的应用程序。这是一款非常简单的回合制游戏,基本上只是记录您按下的按钮并将其发送给其他玩家。由于 Apple 的文档尚未针对 Swift 更新,因此我很难实现所有游戏中心功能。我一直在猜测所有事情并阅读 Objective-C 个示例并希望得到最好的结果(不知何故我设法让一些事情继续进行,尽管我不确定它们是否正确)
无论如何,我同时为我的模拟器和 运行 我的 phone 和模拟器上的应用程序创建了一个新的 iCloud 帐户,试图让它们在游戏中匹配。但是我总是收到 "match request is invalid" 错误:
编辑 我已经在 iTunesConnect 中注册了该应用程序,我已经实现了排行榜并对其进行了测试并且它们有效(所以我假设 iTunesConnect 正常工作和设置)
@IBAction func startTapped(_ sender: Any) {
let request = GKMatchRequest()
request.maxPlayers = 2
request.minPlayers = 1
let mmvc = GKMatchmakerViewController(matchRequest: request)
mmvc?.matchmakerDelegate = self
present(mmvc!, animated: true, completion: nil)
}
extension HomeVC: GKGameCenterControllerDelegate
{
func authenticatePlayer()
{
//CALLED ON VIEWDIDAPPEAR
let localPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {
(view, error) in
if view != nil
{
self.present(view!, animated: true, completion: nil)
} else {
print("AUTHENTICATED!")
print(GKLocalPlayer.localPlayer().isAuthenticated)
}
}
}
func gameCenterViewControllerDidFinish(_ gameCenterViewController: GKGameCenterViewController) {
gameCenterViewController.dismiss(animated: true, completion: nil)
}
}
这是配对代码。请注意,我可以让 Game Center 屏幕出现并告诉我 "how many players" 它缺少一个玩家并提供邀请朋友的选择等等
extension HomeVC: GKMatchmakerViewControllerDelegate {
func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
print("match was cancelled")
viewController.dismiss(animated: true, completion: nil)
}
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) {
print("didFailwithError: \(error.localizedDescription)")
}
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
print("Match found, ID: \(match.description)")
let gameScreenVC = self.storyboard?.instantiateViewController(withIdentifier: "mainGame") as! ViewController
gameScreenVC.providesPresentationContextTransitionStyle = true
gameScreenVC.definesPresentationContext = true
gameScreenVC.modalPresentationStyle = UIModalPresentationStyle.fullScreen
gameScreenVC.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
match.delegate = gameScreenVC
self.present(gameScreenVC, animated: true, completion: nil)
}
}
如果有人遇到这个问题,我通过用相同的数量替换 "minelayers and max-layers" 来修复它,所以代码现在看起来像这样:
@IBAction func startTapped(_ sender: Any) {
let request = GKMatchRequest()
request.maxPlayers = 2 //min and max should be the same
request.minPlayers = 2 //apparently they need to be the same
let mmvc = GKMatchmakerViewController(matchRequest: request)
mmvc?.matchmakerDelegate = self
present(mmvc!, animated: true, completion: nil)
}
显然 Game Center 不喜欢 min.player 计数为 1,它无效。但这就是我停止给我无效匹配请求警告的方式
我正在尝试学习如何构建基于游戏中心的应用程序。这是一款非常简单的回合制游戏,基本上只是记录您按下的按钮并将其发送给其他玩家。由于 Apple 的文档尚未针对 Swift 更新,因此我很难实现所有游戏中心功能。我一直在猜测所有事情并阅读 Objective-C 个示例并希望得到最好的结果(不知何故我设法让一些事情继续进行,尽管我不确定它们是否正确) 无论如何,我同时为我的模拟器和 运行 我的 phone 和模拟器上的应用程序创建了一个新的 iCloud 帐户,试图让它们在游戏中匹配。但是我总是收到 "match request is invalid" 错误:
编辑 我已经在 iTunesConnect 中注册了该应用程序,我已经实现了排行榜并对其进行了测试并且它们有效(所以我假设 iTunesConnect 正常工作和设置)
@IBAction func startTapped(_ sender: Any) {
let request = GKMatchRequest()
request.maxPlayers = 2
request.minPlayers = 1
let mmvc = GKMatchmakerViewController(matchRequest: request)
mmvc?.matchmakerDelegate = self
present(mmvc!, animated: true, completion: nil)
}
extension HomeVC: GKGameCenterControllerDelegate
{
func authenticatePlayer()
{
//CALLED ON VIEWDIDAPPEAR
let localPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {
(view, error) in
if view != nil
{
self.present(view!, animated: true, completion: nil)
} else {
print("AUTHENTICATED!")
print(GKLocalPlayer.localPlayer().isAuthenticated)
}
}
}
func gameCenterViewControllerDidFinish(_ gameCenterViewController: GKGameCenterViewController) {
gameCenterViewController.dismiss(animated: true, completion: nil)
}
}
这是配对代码。请注意,我可以让 Game Center 屏幕出现并告诉我 "how many players" 它缺少一个玩家并提供邀请朋友的选择等等
extension HomeVC: GKMatchmakerViewControllerDelegate {
func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
print("match was cancelled")
viewController.dismiss(animated: true, completion: nil)
}
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) {
print("didFailwithError: \(error.localizedDescription)")
}
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
print("Match found, ID: \(match.description)")
let gameScreenVC = self.storyboard?.instantiateViewController(withIdentifier: "mainGame") as! ViewController
gameScreenVC.providesPresentationContextTransitionStyle = true
gameScreenVC.definesPresentationContext = true
gameScreenVC.modalPresentationStyle = UIModalPresentationStyle.fullScreen
gameScreenVC.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
match.delegate = gameScreenVC
self.present(gameScreenVC, animated: true, completion: nil)
}
}
如果有人遇到这个问题,我通过用相同的数量替换 "minelayers and max-layers" 来修复它,所以代码现在看起来像这样:
@IBAction func startTapped(_ sender: Any) {
let request = GKMatchRequest()
request.maxPlayers = 2 //min and max should be the same
request.minPlayers = 2 //apparently they need to be the same
let mmvc = GKMatchmakerViewController(matchRequest: request)
mmvc?.matchmakerDelegate = self
present(mmvc!, animated: true, completion: nil)
}
显然 Game Center 不喜欢 min.player 计数为 1,它无效。但这就是我停止给我无效匹配请求警告的方式