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.isPeerEnabled = true
The SDK does not report discovered or connected peers to the app. Peer sync runs entirely inside the SDK.
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.
- Verify that devices get connected in the SDK logs — look for debug prints with the
(network) P2Pprefix. SetSkyPath.shared.loggerLevel = .debugto see them, see Logs.
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.