涉及到判斷網(wǎng)絡(luò)請求是WiFi,3G,還是無網(wǎng)絡(luò),有多種方式,我們可以利用AFNetworking提供的方法
//見圖:
//代碼
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
// 提示:要監(jiān)控網(wǎng)絡(luò)連接狀態(tài)顷帖,必須要先調(diào)用單例的startMonitoring方法
[manager startMonitoring];
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
if (status == -1) {
NSLog(@"未識別網(wǎng)絡(luò)");
}
if (status == 0) {
NSLog(@"未連接網(wǎng)絡(luò)");
}
if (status == 1) {
NSLog(@"3G/4G網(wǎng)絡(luò)");
}
if (status == 2) {
NSLog(@"Wifi網(wǎng)絡(luò)");
}