Elad Benda Elad Benda - 6 months ago 16
iOS Question

are there network connectivity callbacks for ios swift?

I want to block my app's ui when there is no network connectivity.

I saw this post about checking network connectivity.

Is there a way to register for a listener with callback

? Instead of creating my own periodic task?

Answer Source

You can use Reachability class to get notification when network status has changed. Refer https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html for documentation as well as sample code on integrating Reachability. It gives you kReachabilityChangedNotification notification which is broadcasted when network status has changed. Once you get the notification you can check whether network is available or not.

You can also refer this How to use reachability class to detect valid internet connection?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download