Apple ドキュメントを使用して、Game Center 経由で 2 人のプレイヤーを接続し、ゲームを開始することに成功しました。しかし、2 人のプレイヤー間でデータを送信するアプリを取得するのに何日も苦労しました。
2 つのプレーヤー間で整数を送信する必要があるだけですが、構造体などを作成した後でも、ドキュメント コードを実行することさえできません。
func sendPosition() {
let messageToSend = 123
//what do I need to do messageToSend to send it?
do {
try match.sendData(toAllPlayers: packet, with: .unreliable)
} catch {
}
if error != nil {
// Handle the error.
}
}
func match(_ match: GKMatch, didReceive data: Data, fromRemotePlayer player: GKPlayer) {
//What do I need to do to receive the data?
}
Swift 5+で実験できる実用的なコードを手伝ってくれる人がいれば、感謝します。