My app uses NWBrowser and NWListener to advertise a service and to discover other peer instances on the local network. It regenerates a serial number with each fresh launch. This serial number is included in TXTRecord. I can see that the serial number correctly changes after every restart.
The problem that is bugging me right now is as follows. If I run the app with the lightning cable connected to my Macbook and then disconnect the cable, the app running on my IPhone would retain the information about my Macbook no matter how many times I restart the app or restart the other peer. It doesn't matter if I close the app before disconnecting the cable or the other way around.
Restarting the app on my Macbook while in this state doesn't refresh the record on my IPhone. The app is supposed to replace the found instances for new and change cases but the old instance always prevails.
I even went into airplane mode and turned off everything wireless on both my IPhone and my macbook. Nothing but services previously advertised by my Macbook still show up, which includes _airplay._tcp
A third-party app for Bonjour discovery also confirms the phantom instances but it was of course unable to resolve these instances. It always takes tens of minutes for the phantom instances to be removed short of a reboot.
I then discovered that if I start the app without the lightening cable connected, this issue wouldn't happen anymore. This suggests to me that this may have to do with the lightning port's network.
The same app (via Mac Catalyst) running on the Macbook does not have this issue.
Has anyone experienced anything similar?