Book Image

iOS and OS X Network Programming Cookbook

By : Jon Hoffman
Book Image

iOS and OS X Network Programming Cookbook

By: Jon Hoffman

Overview of this book

Table of Contents (15 chapters)
iOS and OS X Network Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Checking the network connection type and changes


AFNetworking comes with the AFNetworkReachabilityManager class that makes it very easy to detect the network connection type of the device our application is running on and also notifies us if the connection type changes. This can come in handy if we are creating an application that is heavily reliant on the Internet or has large downloads/uploads that we want to run only when connected to Wi-Fi.

Getting ready

You will need to download and add AFNetworking to your project.

How to do it…

Let's create our reachability client by using the following code:

AFNetworkReachabilityManager *reachability = [AFNetworkReachabilityManager sharedManager];

[reachability setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"----Connection WWAN");
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:...