前提・実現したいこと
swiftで開発をしています。インターネット上に転がっているobject-Cでのコードをswiftに変換してGameCennterの無作為マッチング機能を実装しようとしているのですが、どうもマッチングに成功しません
該当のソースコード
swift
1func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) { 2 self.dismiss(animated: true, completion: nil) 3} 4 5 6func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) { 7 self.dismiss(animated: true, completion: nil) 8} 9 10 11func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) { 12 self.match = match 13 match.delegate = self 14 self.dismiss(animated: true, completion: nil) 15} 16 17 18let match = GKMatch() 19let matchMaker = GKMatchmaker.shared() 20 21 22 @IBAction func connect(_ sender: Any) { 23 let request = GKMatchRequest() 24 request.minPlayers = 2 25 request.maxPlayers = 2 26 27 let mmvc = GKMatchmakerViewController(matchRequest: request) 28 mmvc?.matchmakerDelegate = self 29 if let aMmvc = mmvc { 30 present(aMmvc, animated: true) {() -> Void in } 31 } 32}
試したこと
以上のコードでマッチメークの画面は表示されますが、「今すぐプレイ」を選択すると、エラー「プレイヤーが見つかりませんでした」と表示されるか、あるいは表示されない時でもマッチングは成功しません。GameCenterのランダムマッチング機能の実装経験のある方ご教授お願いいたします。
あなたの回答
tips
プレビュー