The best option for doing this on shipping systems is
NetService
. If you pass in the
.listenForConnections
option when you publish the service, it will listen for connections and call the
netService(_:didAcceptConnectionWith:outputStream:)
delegate method for each one. You can then either:
Use these
InputStream
and OutputStream
instances for your networkingOr, if you have existing BSD Sockets-based networking code, extract the sockets from these streams (using
CFStreamPropertyKey.socketNativeHandle
) and pass that down to you code
On iOS 12 and later you should look in to the Network framework.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"