0

Can anyone please tell me if there is a way to detect when the network connection goes off when the app is in background ?

I want to get a callback when the Wifi-Network is turned off and also when there is switch from Wifi to Cellular network.

I am currently using NEHotspotHelper and I get a callback when Wifi SSID changes. i.e when the device moves from Wifi-A to Wifi-B. I also get a callback when network switches from Cellular to Wifi but not vice versa.

Please help !!

Using the below code to get callbacks.

NEHotspotHelper.register(options: nil, queue: queue, handler: {(_ cmd: NEHotspotHelperCommand) -> Void in
            network = cmd.network!
            if network.didJustJoin {

            }
        })
Preetham Baliga
  • 271
  • 2
  • 4
  • 15

1 Answers1

0

You can use Reachability Library for checking the network connection state. https://developer.apple.com/library/content/samplecode/Reachability/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007324-Intro-DontLinkElementID_2

You can follow the below tutorial also in order to know how to achieve it. https://medium.com/@sauvik_dolui/network-status-monitoring-on-ios-part-1-9a22276933dc

Abhishek
  • 3,304
  • 4
  • 30
  • 44