简体   繁体   中英

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 "onNetworkLost()" , "onNetworkAvailable()" ? Instead of creating my own periodic task?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM