Multipeerconnectivity on iOS with Xcode
Asked Answered
E

3

5

Both devices advertising and browsing. The problem occurs when trying the establish a connection.

func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) {}

Does working when trying to connect but after few seconds, it's been calling again with MCSessionState == .notConnected .

Tried both with WiFi, BT, and every combination in between...

Just added:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
    <false/>
</dict>

Did not helped much... Still getting in the console (just on the iOS 10.2 device, though...):

2017-02-06 15:17:37.858063 Advertiser[1149:316236] [ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (1724768204)
2017-02-06 15:17:39.727633 Advertiser[1149:316295] [ViceroyTrace] [ICE][ERROR]  Send BINDING_REQUEST failed(C01A0041).
2017-02-06 15:17:39.808822 Advertiser[1149:316295] [ViceroyTrace] [ICE][ERROR]  Send BINDING_REQUEST failed(C01A0041).
2017-02-06 15:17:39.948454 Advertiser[1149:316295] [ViceroyTrace] [ICE][ERROR]  Send BINDING_REQUEST failed(C01A0041).
2017-02-06 15:17:40.179569 Advertiser[1149:316295] [ViceroyTrace] [ICE][ERROR]  Send BINDING_REQUEST failed(C01A0041).
2017-02-06 15:17:40.591829 Advertiser[1149:316295] [ViceroyTrace] [ICE][ERROR]  Send BINDING_REQUEST failed(C01A0041).
2017-02-06 15:17:41.297454 Advertiser[1149:316295] [ViceroyTrace] [ICE][ERROR]  Send BINDING_REQUEST failed(C01A0041).
2017-02-06 15:17:42.547840 Advertiser[1149:316295] [ViceroyTrace] [ICE][ERROR]  Send BINDING_REQUEST failed(C01A0041).
2017-02-06 15:17:44.077537 Advertiser[1149:316295] [ViceroyTrace] [ICE][ERROR]  Send BINDING_REQUEST failed(C01A0041).
2017-02-06 15:17:45.601568 Advertiser[1149:316295] [ViceroyTrace] [ICE][ERROR]  Send BINDING_REQUEST failed(C01A0041).
2017-02-06 15:17:47.125030 Advertiser[1149:316295] [ViceroyTrace] [ICE][ERROR]  Send BINDING_REQUEST failed(C01A0041).
2017-02-06 15:17:48.110301 Advertiser[1149:316267] [GCKSession] Not in connected state, so giving up for participant [66CDDFCC] on channel [0].
2017-02-06 15:17:48.111331 Advertiser[1149:316267] [GCKSession] Not in connected state, so giving up for participant [66CDDFCC] on channel [1].
2017-02-06 15:17:48.111526 Advertiser[1149:316267] [ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (1724768204)
2017-02-06 15:17:48.111705 Advertiser[1149:316267] [GCKSession] Not in connected state, so giving up for participant [66CDDFCC] on channel [2].
2017-02-06 15:17:48.111873 Advertiser[1149:316267] [ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (1724768204)
2017-02-06 15:17:48.112042 Advertiser[1149:316267] [GCKSession] Not in connected state, so giving up for participant [66CDDFCC] on channel [3].
2017-02-06 15:17:48.113031 Advertiser[1149:316267] [ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (1724768204)
2017-02-06 15:17:48.121016 Advertiser[1149:316267] [GCKSession] Not in connected state, so giving up for participant [66CDDFCC] on channel [4].
2017-02-06 15:17:48.121321 Advertiser[1149:316267] [ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (1724768204)
2017-02-06 15:17:48.121506 Advertiser[1149:316267] [GCKSession] Not in connected state, so giving up for participant [66CDDFCC] on channel [5].
2017-02-06 15:17:48.121683 Advertiser[1149:316267] [ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (1724768204)

(Advertiser is the name of the app) Using iPhone 6S with 10.2 & iPhone 6 with 9.2. Running code on Macbook Pro with macOS Sierra v10.12.2 from Xcode 8.2.1 (Swift3).

Exact answered 6/2, 2017 at 13:43 Comment(0)
N
4

I had the same problem and I found a solution. It still shows some errors but it works for me.

Try initialising MCSession as follows:

let mcSession = MCSession(peer: self.mcPeerId, securityIdentity: nil, encryptionPreference: .none)

then implement MCSession's certificate handler delegate method as follows:

func session(_ session: MCSession, didReceiveCertificate certificate: [Any]?, fromPeer peerID: MCPeerID, certificateHandler: @escaping (Bool) -> Void) {
    certificateHandler(true)
}
Neomineomycin answered 9/12, 2017 at 17:13 Comment(1)
yeah this also worked for me. thx manPuerperal
E
3

Did you keep a reference to the MCSession object for both advertiser and browser? Those BINDING_REQUEST failed messages do occur if an in-use MCSession object gets deallocated.

Etherize answered 6/7, 2017 at 8:28 Comment(0)
K
1

If both devices continue to advertise and browse after making a connection they may disconnect when they re-discover each other. Right after making a connection, turn off browsing by calling:

MCNearbyServiceBrowser.stopBrowsingForPeers()

If the devices continue to advertise, other devices can still connect to them.

Kerb answered 3/3, 2017 at 1:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.