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;
}].