Swift---網路判斷封裝(可直接使用)

來源:互聯網
上載者:User
import Foundationclass YJNetWorkManager: NSObject {    /**     判斷網路類型     - returns:傳回值字串 wifi(kReachableViaWiFi) 移動網網路(kReachableViaWWAN) 無網路(kNotReachable)     */    class func rechabilityWith2GAnd3GAndWifi() ->String {        let reachability = Reachability.reachabilityForInternetConnection()        if reachability!.isReachableViaWiFi() {            return kReachableViaWiFi        } else if reachability!.isReachableViaWWAN() {            return kReachableViaWWAN        } else {            return kNotReachable        }    }    /**     判斷網路是否可用     - returns: true 可用 false 不可用     */    class func JudgeNetWork() ->Bool {        let reachability = Reachability.reachabilityForInternetConnection()        if reachability!.isReachable() {            return true        } else {            return false        }    }}
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.