swift 检测网络状态

swift 检测网络状态_第1张图片
Alamofire

```

letNetworkManager =NetworkReachabilityManager(host:"www.baidu.com")

NetworkManager!.listener= { statusin

print("")

switchstatus {

case.NotReachable:

print("NotReachable")

case.Unknown:

print("Unknown")

case.Reachable(.EthernetOrWiFi):

print("EthernetOrWiFi")

self.ifCanDownload()

case.Reachable(.WWAN):

letuserDefault =NSUserDefaults.standardUserDefaults()

lettraffic = userDefault.boolForKey("TrafficDownloadAlerts")

iftraffic {

letalertView =UIAlertView()

alertView.title="系统提示"

alertView.message="现在不是Wifi网络,您确定要下载吗?"

alertView.addButtonWithTitle("取消")

alertView.addButtonWithTitle("确定")

alertView.cancelButtonIndex=0

alertView.delegate=self;

alertView.show()

}else{

self.ifCanDownload()

}

print("WWAN")

}

}

NetworkManager!.startListening()

```

你可能感兴趣的:(swift 检测网络状态)