created an iOS application which use Network.framework to connect other peer devices and then try to sync information. Everything seems working fine except one problem which is related to background mode.
Steps are here :
- Device1 connected with Device2
- sending data through Device1 , immediately i can see same data sync in Device2
- When Device2 put into the background mode and Device1 sending data , Device2 once come into foreground mode ,not able to receive data. [ how can i ensure data receive in other Device2 successfully once it come online [ or operate in foreground mode]
Kindly help
1. is the Network framework solely for user-centric activities where sessions must be started and maintained with foreground app usage and it doesn't support background activity ?
The thing to keep in mind with networking in iOS is that the background/foreground state isn’t key, but rather the suspended/running state. Networking works just fine as long as your process is running. Once it’s suspended, everything just stops [1].
Now this does tie into the background/foreground state because iOS are typically suspended when they move to the background. However, there are circumstances where that doesn’t happen, for example, an audio streaming app.
Whether this distinction is relevant to your app is hard to say without knowing more about your app.
2. Application coming from background and not able to receive data , how to ensure this ? ( In other words how to handle the reconnection issue ) do we need to find some sort of algorithm to handle this ?
Network framework doesn’t do anything to help you out here. If you want to handle this, you’ll need to structure your code to do so. One key part of that is being able to uniquely identify your peers, so that you know that the connection by peer A is a reconnection of peer A, not a new connection from peer B.
Don’t use the IP addresses to uniquely identify peers. Those change all the time.
3. Is there any limitation of how many devices can work in peer to peer using Network framework ?
There’s no limitation imposed by Network framework.
There are practice limitations imposed by the underlying link layer. For example, putting 100,000 devices on a single Wi-Fi network is not going to work. The practical limit for infrastructure Wi-Fi is significantly higher than the practical limited for peer-to-peer Wi-Fi.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Except for networking being done by other processes on your behalf, the most common of which is NSURLSession
background sessions, which are run by a system process (nsurlsessiond
).