2

I'm trying to restart my MCNearbyServiceAdvertiser with different discoveryInfo but the old discoveryInfo seems to remain despite completely replacing the advertiser instance with a new one with the new info. If I change it multiple times, ServiceBrowsers tend to see the discovery information of the previously active ServiceAdvertiser rather than the currently a active one.

let oldDiscoveryInfo = ["playerName": "Dave"]
self.serviceAdvertiser = MCNearbyServiceAdvertiser(peer: PeerID.shared.myPeerID,
                                                  discoveryInfo: discoveryInfo,
                                                  serviceType: "SpinHost")
self.serviceAdvertiser.startAdvertisingPeer()


//Now change the discovery info
serviceAdvertiser.stopAdvertisingPeer()
let newDiscoveryInfo = ["playerName": "Steve"]
self.serviceAdvertiser = MCNearbyServiceAdvertiser(peer: PeerID.shared.myPeerID,
                                                  discoveryInfo: newDiscoveryInfo,
                                                  serviceType: "SpinHost")
self.serviceAdvertiser.startAdvertisingPeer()

I've tried adding a delay to staring up the new ServiceAdvertiser but it still doesn't seem to help. Any ideas?

3
  • 2
    If it is an option for you, you could renew your peer ID. This seems to work for me. Jun 1, 2020 at 14:21
  • Ooo! Very interesting! Thanks for letting me know. I'll give that a go but that sounds really promising! Thanks a bunch! Jun 2, 2020 at 15:44
  • @BartWesselink you solved my issue. Thanks, really appreciate your help! Jun 8, 2020 at 9:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.