Peer-to-peer Sync
SkyPath supports Peer-to-peer sync of cached data between devices running the SkyPath app or SDK.
This feature saves the network consumption when more than one device is running the SkyPath service in the cockpit.
A connection is established when both apps are in the foreground and remains active when moved to the background. However, iOS can disconnect devices in some circumstances. To reconnect, apps should be in the foreground.
Multiple connections can be kept at the same time. Each device will share data with other connected devices.
Setup
Apple's MultipeerConnectivity framework is used to discover and communicate between devices in the local network.
- Add
NSLocalNetworkUsageDescriptionto Info.plist
<key>NSLocalNetworkUsageDescription</key>
<string>You can save network consumption by allowing SkyPath to find and connect to devices on your network. SkyPath will share the turbulence information between the devices.</string>
- Add Bonjour service to
NSBonjourServices
<key>NSBonjourServices</key>
<array>
<string>_skypath-peer._tcp</string>
</array>
- Enable feature flag. Can be toggled at any time.
SkyPath.shared.peerEnabled = true
- Optionally implement a delegate callback.
// SkyPathDelegate
func didUpdatePeers(discovered: [String], connected: [String]) {
// optionally update a status that someone has been discovered or connected
}
Test
Test that devices get connected.
- Run the app on the device, and you should see a system permission alert to allow the app to find local devices. Allow.
- Run the app on another device, connected to the same WiFi network. Allow to find local devices.
- Apps should call
SkyPathDelegate.didUpdatePeersdelegate. Verify that devices get connected.
Also, in the logs could see debug prints with (network) P2P prefix.
Optionally, to test that data is actually being shared, you can do the following.
- Keep one device online via WiFi.
- Keep the other device connected to the same WiFi. Block the SkyPath API on it or an internet connection at all.
- Load a flight corridor or a viewport on an online device for an area that was not viewed on an offline device. See map data.
- Load the same area on an offline device. Wait a bit. The data should appear. If not, make sure devices are connected and try again.