LoginSignup
27
26

More than 5 years have passed since last update.

Alamofireでオフライン判定をする方法

Last updated at Posted at 2016-10-23

前置き

iOSアプリを開発していたら、通信状況を確認することがよくあります。
有名なライブラリとしてはReachabilityがありますが、本日はAlamofireでもそういったことができるので紹介します。

方法

let net = NetworkReachabilityManager()
net?.startListening()
        if  net?.isReachable ?? false {

            if ((net?.isReachableOnEthernetOrWiFi) != nil) {
                //do some
                print("isReachableOnEthernetOrWiFi")


            }else if(net?.isReachableOnWWAN)! {
                //do some
                print("isReachableOnWWAN")

            }
        } else {
            //オフライン
            print("no connection")

        }

上記の方法で、Alamofireで通信状況を確認できます。

27
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
26