Skip to content

Session doesn't connect to peers #15

Description

@chaert-s

Hi,
I have this running on 2 physical devices but when I try to connect them, I simply get this in the Xcode cmd output:
Not in connected state, so giving up for participant [48c78cc] on channel [0]. Not in connected state, so giving up for participant [48c78cc] on channel [1]. Not in connected state, so giving up for participant [48c78cc] on channel [2].

The peers never connect to each other. Is there anything I need to consider aside from initializing the session? I am currently doing it like in the sample app (which works fine on both devices)

import Foundation
import SwiftUI
import Foundation
import MultipeerConnectivity


struct tutorialView: View {
    @State var delegate = multidelegate()
    var body: some View {
        Text("Peers connected: \(delegate.multipeerHelp?.connectedPeers.count ?? 999)").onAppear(){
            delegate.setupMultipeer()
        }
    }
}

class multidelegate: MultipeerHelperDelegate{
    var multipeerHelp: MultipeerHelper!
    func setupMultipeer() {
        multipeerHelp = MultipeerHelper(
            serviceName: "demo",
            sessionType: .both,
            delegate: self
        )
    }
    func receivedData(_ data: Data, _ peer: MCPeerID) {
      print(String(data: data, encoding: .unicode) ?? "Data is not a unicode string")
    }

    func peerJoined(_ peer: MCPeerID) {
      print("new peer has joined: \(peer.displayName)")
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions