Lightweight wrapper around NSNetService for use in iOS apps. Enables discovering other devices over standard LAN and ad-hoc peer-to-peer WiFi or Bluetooth networks.
Written in Swift 3.
When nearby devices are discovered and properly resolved, Servus provides a hostname for each of them. Combine it with a HTTP Server for iOS, and HTTP requests, and BAM! You send data between devices using Bluetooth or WiFi without having to worry about the infrastructure.
Apple provides a framework for such ad-hoc networks. However, from my experience it's quite unreliable (gets stuck pretty often), and is painful to test.
Servus, on the other hand, provides only the discovery phase. Data transfer is done separately, so the developer has greater insight to it. Also, it's super easy to test! Just open the app on the simulator, or on a device within the same LAN as your computer and you can send HTTP requests to http://your-device-hostname:PORT/
. And it works. Magic.
explorer = Explorer()
explorer.delegate = self
explorer.startExploring() // Start announcing this device's presence & reporting discovery of other ones.
...
func explorer(explorer: Explorer, didDeterminePeer peer: Peer) {
print("Determined hostname for \(peer.identifier): \(peer.hostname!)")
}
For working example check out the app target.
Servus can be integrated with Xcode project via Carthage, a dependency manager for Cocoa.
- Add
github "airalex/Servus"
to your Cartfile. - Run
carthage update
- Drag
Carthage/Build/iOS/Servus.framework
to your Xcode project, or select File > Add Files... - Make sure
/usr/local/bin/carthage copy-frameworks
Run Script phase is present for your target. - Add
$(SRCROOT)/Carthage/Build/iOS/Servus.framework
to Input Files list.
git clone [email protected]:airalex/Servus.git
- Copy Servus/ directory to your project.
- Make sure all files are present in your project (Explorer, Peer, Advertiser, Resolver, Revealer).