I created a session, shared it to another player and now I want to start a game. I can see a session with two players on both devices. So, it looks like we're ready to game but I need to change connected status before the game and I can do this on both devices.
But... when I do this on device A, I see that user A is connected and user B isn't. And after that, when I repeat the process on device B, I see vice versa situation. B is connected and A is not.
Here is my code that connect player and send the data:
session.setConnectionState(.connected) { (error) in
if let err = error {
assertionFailure(err.localizedDescription)
}
else {
print("NC:",session.players(with: .notConnected))
print(" C:",session.players(with: .connected))
let m = MoveTransfer(move:1) // test struct to send/receive data
session.send(m.data(), with: .reliable) { (error) in
if let err = error {
assertionFailure(err.localizedDescription)
}
}
}
}
I'm getting error:
The requested operation could not be completed because there are no recipients connected to the session
By the way, I'm unable to change connected state on the simulator (iCloud is logged in).
I forgot to mention, that I'm working on a turn based game.
Edit
Tried again and now after several iterations I got this:
I have both players connected to session. But send data still doesn't work.
here is console output:
NC: [] // not connected array and connected array below
C: [<GKCloudPlayer: 0x17402e700>, id: playerID1, name: Player1,<GKCloudPlayer: 0x17402e900>, id: playerID2, name: Player2]
fatal error: The requested operation could not be completed because there are no recipients connected to the session.
Got this on two real devices.