2

I am using the Multipeer Connectivity framework to connect multiple users in my app. When I try to invite users via the MCBrowserViewController, it works. However, when I try to send data I get the following error:

2022-10-29 13:13:30.159840+0200 Split[72183:5177674] [MCNearbyServiceAdvertiser] We are trying to send data to peer [iPhone,0D8E401A] and we are not connected.
2022-10-29 13:13:38.313487+0200 Split[72183:5177663] [GCKSession] Not in connected state, so giving up for participant [0D8E401A] on channel [0].

This is my code to send data:

func sendPayData(totalUser: String) {
        if mcSession.connectedPeers.count > 0 {
                do {
                    try mcSession.send(totalUser.data(using: .ascii)!, toPeers: mcSession.connectedPeers, with: .reliable)
                    
} catch let error as NSError {
                    let ac = UIAlertController(title: "Send error", message: error.localizedDescription, preferredStyle: .alert)
                    ac.addAction(UIAlertAction(title: "OK", style: .default))
                    present(ac, animated: true)
                }
        }
    }

One solution at the Apple Developer Forum was to set the encryptionPreference to .none in the MCSession. This did not help me either. Some also say that they can send data despite this error. Not for me, unfortunately, as it looks.

I found a few questions about this error on Reddit, but they weren't answered there. I would be very grateful if someone could help me.

JS__2008
  • 31
  • 1
  • Were you able to solve this? I have almost the same issue, see: https://stackoverflow.com/questions/76656734/not-being-able-to-keep-connection-stable-and-send-data-across-devices-using-mult – oneshot Jul 10 '23 at 21:07

0 Answers0