Scanning for Connectivity Changes
Connectivity state may change while an application is running. Checking once at application launch usually isn’t enough for an application that depends on data connections throughout its lifetime. When a network connection is lost or when it can finally be established, your UI should adjust accordingly, such as disabling or enabling a button or alerting the user.
Listing 13-1 addresses this challenge by extending the UIDevice
reachability category to monitor network changes. It provides a pair of methods that allow you to schedule and unschedule reachability watchers—observers that notify when the connectivity state changes. It builds a callback that messages a watcher object when that state changes. The monitor ...
Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.