MCNearbyServiceAdvertiser Server did not publish
Asked Answered
R

1

6

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;
}].
Rozellarozelle answered 18/6, 2022 at 3:38 Comment(1)
you should show a minimal reproducible example or at least some reasonable relevant code, see info here: stackoverflow.com/help/minimal-reproducible-example Then, show us on which line of your code you get the error.Infringement
B
6

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.

Buckshee answered 21/6, 2022 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.