MCNearbyServiceAdvertiser on macOS 10.13 (High Sierra) not working
Asked Answered
C

1

9

I am trying to advertise a service with Multipeer Connectivity in macOS 10.13 as such:

    override init() {
    self.serviceAdvertiser = MCNearbyServiceAdvertiser(peer: peerID, discoveryInfo: nil, serviceType: serviceID);
    super.init();
    self.serviceAdvertiser.delegate = self;
    self.serviceAdvertiser.startAdvertisingPeer();
}

where

    private let serviceID = "sample-test";
private let peerID = MCPeerID(displayName:  Host.current().localizedName!);

Instead of getting the proper delegate callback methods getting called the advertiser immediately fails and this is what I get in the console:

2017-10-16 11:22:35.568607-0700 macApp[3060:288948] [] tcp_listener_socket_create bind(fd 3) failed: [1] Operation not permitted
2017-10-16 11:22:35.569223-0700 macApp[3060:288940] [MCNearbyServiceAdvertiser] Server did not publish: errorDict [{
    NSNetServicesErrorCode = 1;
    NSNetServicesErrorDomain = 1;
}].

Any idea how to solve this?

UPDATE:

Running the exact same code in an iOS Simulator works fine so I'm guessing it has something to do with some permissions on the Mac machine.

Seeing that the log says that this is a permission issue I went ahead and enabled the root user on the Mac and tried running the same code to no avail.

I am thinking of turning off System Integrity Protection but I have a hard time coming to terms with the fact that Apple would publish this framework if all these security compromises are required in order to use it. Will keep investigating.

Clarettaclarette answered 16/10, 2017 at 18:29 Comment(0)
C
20

After days of struggle the solution is very simple. Make sure you enable the networking entitlements for your target. See attached snapshot:

enter image description here

Clarettaclarette answered 18/10, 2017 at 18:12 Comment(3)
same for OSX Mojave and sift 5. :)Canicular
I also need this trick for my Swift 5 + Xcode 12 + macOS 11 Big Sur combination. Thanks.Went
Can't thank you enough :-)Pomerleau

© 2022 - 2024 — McMap. All rights reserved.