Currently I’m developing an application which can send multiple files to other device over Wi-Fi using bonjour service same as developer.apple Wi-Tap application did. Only one difference is ,I’m sending files where Wi-Tap sending strings.
Now I would like to handle the Wi-Fi connection issues like connection loss in my application.
I can handle the NSStream Errors through handleEvent delegate for below cases
NSStreamEventErrorOccurred
NSStreamEventEndEncountered
However I’m Unable to find the Wi-Fi connection loss through this delegate. So the possible solutions in my mind is using the Reachability class for checking the wi-fi connection in a background thread. However it’s a bad practice and it consumes more battery power of device.
So is there any other way to track the Wi-Fi connection of the device during the file transfer ?
One way around is to use use NSNetService
As this is just a service publishing tool it won’t interfere in your data transfer so you just have to use
You have to run this in
if Wifi is on then this will be fired
if there is no wifi
These are the delegates of NSNetService you can refer the library .
This is just a way around your problem hope it helps.