swift 3.0 TViOS 10.0 MultipeerConnectivity works, but with errors
Asked Answered
S

5

12

Using this code to setup Multipeer connectivity under TViOS 10.0.

import UIKit
import MultipeerConnectivity

class MPCHandler: NSObject, MCSessionDelegate {

var peerID: MCPeerID!
var session: MCSession!
var browser: MCBrowserViewController!
var advertiser: MCAdvertiserAssistant? = nil

func setupPeerWithDisplayName (displayName: String) {
    peerID = MCPeerID(displayName: UIDevice.current.name)
}

func setupSession() {
    session = MCSession(peer: peerID)
    session.delegate = self
}

func setupBrowser() {
    browser = MCBrowserViewController(serviceType: "my-game", session: session)
}

func advertiseSelf(advertise:Bool) {
    if advertise {
        advertiser = MCAdvertiserAssistant(serviceType: "my-game", discoveryInfo: nil, session: session)
        advertiser!.start()
    } else {
        advertiser!.stop()
        advertiser = nil
    }
}

public class MyClass {
    static let myNotification = Notification.Name("MPC_DidChangeStateNotification")
}

public class MyClass2 {
    static let myNotification = Notification.Name("MPC_DidRecieveDataNotification")
}

func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) {
    let userInfo = ["peerID":peerID,"state":state.rawValue] as [String : Any]
    DispatchQueue.main.async {
        NotificationCenter.default.post(name: MyClass.myNotification, object: nil, userInfo: userInfo)
    }
}
func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) {
    let userInfo = ["data":data, "peerID":peerID] as [String : Any]
    DispatchQueue.main.async {
        NotificationCenter.default.post(name: MyClass2.myNotification, object: nil, userInfo: userInfo)
    }
}
func session(_ session: MCSession, didFinishReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, at localURL: URL, withError error: Error?) {
    // code
}
func session(_ session: MCSession, didStartReceivingResourceWithName resourceName: String, fromPeer peerID: MCPeerID, with progress: Progress) {
    // code
}
func session(_ session: MCSession, didReceive stream: InputStream, withName streamName: String, fromPeer peerID: MCPeerID) {
    // code
}

}

Reports connected, but I get this errors? Both devices TViOS and iPhone on the same network.

2016-09-08 11:13:13.602572 PeerCodeATV[172:7628] [ViceroyTrace] [ICE][ERROR]     ICEStopConnectivityCheck() found no ICE check with call id (1969443468)
2016-09-08 11:13:17.168110 PeerCodeATV[172:7686] [ViceroyTrace] [ICE][ERROR]    Send BINDING_REQUEST failed(C01A0041).
2016-09-08 11:13:18.044156 PeerCodeATV[172:7686] [ViceroyTrace] [ICE][ERROR]    Send BINDING_REQUEST failed(C01A0041).
2016-09-08 11:13:18.766040 PeerCodeATV[172:7686] [ViceroyTrace] [ICE][ERROR]    Send BINDING_REQUEST failed(C01A0041).
2016-09-08 11:13:20.015846 PeerCodeATV[172:7686] [ViceroyTrace] [ICE][ERROR]    
2016-09-08 11:13:24.453030 PeerCodeATV[172:7588] [GCKSession] Not in connected state, so giving up for participant [7563528C] on channel [0].
2016-09-08 11:13:24.476176 PeerCodeATV[172:7588] [GCKSession] Not in connected state, so giving up for participant [7563528C] on channel [1].
2016-09-08 11:13:24.498394 PeerCodeATV[172:7588] [ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (1969443468)
2016-09-08 11:13:24.498840 PeerCodeATV[172:7588] [GCKSession] Not in connected state, so giving up for participant [7563528C] on channel [2].
2016-09-08 11:13:24.522667 PeerCodeATV[172:7588] [ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (1969443468)
2016-09-08 11:13:24.522954 PeerCodeATV[172:7588] [GCKSession] Not in connected state, so giving up for participant [7563528C] on channel [3].
2016-09-08 11:13:24.545934 PeerCodeATV[172:7588] [ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (1969443468)

I already tested the code iOS to iOS, it works perfectly across the same iOS, but iPad running iOS 9.2 -> TViOS 10.0 I see these errors?

It works if I reboot the AppleTV with these errors, subsequent connections however fail!!

Shrift answered 8/9, 2016 at 9:19 Comment(6)
I see the same for iOS 10 to iOS 10Gobioid
Logged a support call with Apple on this... waiting for a response.Shrift
cool, please post back the result :) I did more testing yesterday with two iOS 10 devices: it seems that on iOS 10, bluetooth-only multipeer is completely broken. I mean that multipeer on iOS 10 seems to only work when wifi is turned on. Crazy.Gobioid
in my case, instead of: _mpcSession = [[MCSession alloc] initWithPeer:self.mpcPeerID]; i used: _mpcSession = [[MCSession alloc] initWithPeer:self.mpcPeerID securityIdentity:nil encryptionPreference:MCEncryptionNone]; Lumbricalis
Have you found any solution?Marjie
No, although I seem to be able to ignore it since everything works, even if it is spitting out errors left, right and center. No response from Apple Support in almost a month past now.Shrift
V
8

Resolving the incompatible encryption preference error

I confirm that yonivav was on the right track when encountering the following error during connection of peers:

[MCSession] Peer [DisplayName] has incompatible encryption preference [Required].

However, setting the session encryption preference to .none did not work for me. At https://developer.apple.com/reference/multipeerconnectivity/mcsession/1407000-init it is stated that

On apps linked on or after iOS 9, the encryption is set to required. On apps linked prior to iOS 9, the encryption is set to optional.

Since I was using one client at iOS 10.1 and another client with a lower iOS version, I initialized the session using

var session = MCSession(peer: ownPeerID, 
                        securityIdentity: nil, 
                        encryptionPreference: .optional)

and the connection works reliably again.

Bluetooth issues

However, I must confirm that the connection is not established using Bluetooth only. The invitation is sent and accepted, the connection state changes to connecting and then to not connected 10 seconds later. Right after changing the state to connecting a

[ViceroyTrace] [ICE][ERROR] ICEStopConnectivityCheck() found no ICE check with call id (108154439)

error is thrown.

If I turn on Wifi and Bluetooth on the the iOS 10.1 device, the Bluetooth only device is discovered, followed by a dozen

[ViceroyTrace] [ICE][ERROR] Send BINDING_REQUEST failed(C01A0041).

errors and a connection state change to not connected.

Update to iOS 10.1.1: still broken

I updated the iPhone from iOS 10.1 to 10.1.1, and the errors still persist, no changes at all.

Update to iOS 10.2.1: seems to work!

After the update from 10.2 (where it was still broken) to 10.2.1, it seems to work again (tested with one device using 10.2.1, the other device was an old iOS 8 device. A colleague tested with 10.2.1 and 10.2 and oddly it worked too)! The connection is established when using Bluetooth only (disabling WiFi). However, at times I still get all the ICE-errors and connection errors in the log, BUT not always. Right now I tried to reproduce them and it runs without warnings. Strange, but the good news is: it seems like Apple fixed the issue!

Votive answered 3/11, 2016 at 1:37 Comment(1)
Can anyone confirm my findings that it works again with 10.2.1?Votive
L
4

in my case, instead of:

_mpcSession = [[MCSession alloc] initWithPeer:self.mpcPeerID];

i used:

_mpcSession = [[MCSession alloc] initWithPeer:self.mpcPeerID securityIdentity:nil encryptionPreference:MCEncryptionNone];

Lumbricalis answered 29/9, 2016 at 6:56 Comment(0)
G
3

Multipeer in iOS 10 is a bag of hurt. I did testing yesterday and it seems like it will only work if wifi is turned on (bluetooth-only is broken).

As an alternative to Multipeer, you can use the dns_sd (Bonjour) approach and build your own. I made a framework (Pod) that does exactly this (it mimicks Multipeer). It is unicast not multicast, but supports roles and bluetooth-only. More info here: https://github.com/xaphod/Bluepeer . I'm afraid I have not tested with tvOS, so it might need some work. Pull-requests welcome ;)

Gobioid answered 16/9, 2016 at 15:0 Comment(2)
Noooooooooooooooo!Dada
I've confirmed xaphod's result. Filed a bug (rdar://28388060) with Apple. The bug is readily reproducible with Apples MultipeerGroupChat sample app.Dada
S
3

Got an answer from Apple. Seems you can ignore these messages; they are a side effect related to logging changes it seems?

Watch this for details of the logging changes...

(If you’re curious about this change, check out this video from WWDC 2016: https://developer.apple.com/videos/play/wwdc2016/721/ ).

Shrift answered 5/11, 2016 at 15:33 Comment(0)
L
1

Into my app I developer the feature: stream videos between two iOS device.I cannot stream video to another device,and I got the same log message as you, And I think the problem is as the log said:

[ERROR] ProcessEvent:1199 Send BINDING_REQUEST failed(C01A0041). [ERROR] ICEStopConnectivityCheck:2688 ICEStopConnectivityCheck() found no ICE check with call id But after many time tried debug I figure out that I declared the wrong function of the delegate AVCaptureVideoDataOutputSampleBufferDelegate. After corrected the delegate function then I can stream video between two iOS device -> Done task

But I still got the same log as before. So I think if the feature is work then we can ignore the log message, or report it to Apple. I already report this bug to Apple.

Lotti answered 31/8, 2017 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.