在斷網(wǎng)的情況下使用APP時(shí)瓣窄,會(huì)彈出一個(gè)提示框告訴你沒(méi)有網(wǎng),那么纳鼎,是怎么實(shí)現(xiàn)的呢康栈?下面是代碼。
首先要導(dǎo)入一個(gè)頭文件#import "Reachability.h"(注意:這個(gè)頭文件的類在網(wǎng)上搜"iOS判斷網(wǎng)絡(luò)"就能搜到了)
BOOL isExistenceNetwork = YES;
Reachability *reach = [Reachability reachabilityForInternetConnection];
switch ([reach currentReachabilityStatus]) {
case NotReachable:{
isExistenceNetwork = NO;
NSLog(@"`````````網(wǎng)絡(luò)不給力");
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"當(dāng)前無(wú)網(wǎng)絡(luò)" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionOK = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:actionOK];
[self presentViewController:alert animated:YES completion:^{
}];
break;
}
case ReachableViaWiFi:{
isExistenceNetwork = YES;
break;
}
case ReachableViaWWAN:{
isExistenceNetwork = YES;
break;
}
}
這樣就能實(shí)現(xiàn)了