问题
I noticed that Pasteboard, a clipboard app for iOS, can run Bonjour service in the background. I've no idea how they implement that, so I searched on the Internet and then found that it plays a silent sound file when in background. But it is not true now, because I can't see the app icon on the iPod management screen. How could they do that? Any ideas? Thank you in advance.
Kai.
回答1:
You could, in theory, mark your application as needing to run in the background continuously (for VoIP, or mapping). I've done something this in a proof of concept and it worked great.
Alternatively, this document seems to document how to do networking in the background.
回答2:
Cancel any Bonjour-related services before being suspended. When your app moves to the background, and before it is suspended, it should unregister from Bonjour and close listening sockets associated with any network services. A suspended app cannot respond to incoming service requests anyway. Closing out those services prevents them from appearing to be available when they actually are not. If you do not close out Bonjour services yourself, the system closes out those services automatically when your app is suspended. https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
来源:https://stackoverflow.com/questions/6345554/bonjour-in-the-background