MCNearbyServiceAdvertiser Server did not publish

747 Views Asked by At

I created a Swift project using the Multipeer Connectivity class. I used MCNearbyServiceAdvertiser.

import UIKit
import MultipeerConnectivity

class TestMutilpeer: NSObject {
    
    var SERVICE_NAME  = "probonjore-tcp"
    var ACK_SERVICE_NAME = "abc-txtchat"
    
    var peer: MCPeerID!
    var session: MCSession!
    var serviceAdvertiser: MCNearbyServiceAdvertiser!
    
    override init() {
        super.init()
        
        let peer = MCPeerID(displayName: UIDevice.current.name)
        
        session = MCSession(peer: peer)
        
        let serviceAdvertiser = MCNearbyServiceAdvertiser(peer: peer, discoveryInfo: nil, serviceType: ACK_SERVICE_NAME)
        serviceAdvertiser.startAdvertisingPeer()
    }
}

And the corresponding permission is added in the info (image)

But it still reports an error:

[MCNearbyServiceAdvertiser] Server did not publish: errorDict [{
    NSNetServicesErrorCode = "-72008";
    NSNetServicesErrorDomain = 10;
}].
1

There are 1 best solutions below

0
M. Simms On

Try changing the service name in your plist file to _abc-txtchat._tcp. The value in the plist file has to conform to the Bonjour naming convention while you should continue using abc-txtchat while constructing MCNearbyServiceAdvertiser.