鏈接網(wǎng)絡(luò).png
#import <CoreTelephony/CTCellularData.h>
// MARK: ----- 檢測app是否授權(quán)網(wǎng)絡(luò)狀態(tài)
- (void)networkState
{
CTCellularData *cellularData = [[CTCellularData alloc] init];
cellularData.cellularDataRestrictionDidUpdateNotifier = ^(CTCellularDataRestrictedState state) {
BOOL _isRestricted = YES;
// 獲取聯(lián)網(wǎng)狀態(tài)
switch(state) {
case kCTCellularDataRestricted:
//NSLog(@"Restricted");// 拒絕
break;
case kCTCellularDataNotRestricted:
//NSLog(@"Not Restricted");// 允許
_isRestricted = NO;
break;
case kCTCellularDataRestrictedStateUnknown:
//NSLog(@"Unknown");// 未知
break;
default:
break;
};
if (_isRestricted)
{
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您未授權(quán)連接網(wǎng)絡(luò)嵌莉,可以在“設(shè)置->App->無線數(shù)據(jù)”中開啟“無線數(shù)據(jù)”,連接網(wǎng)絡(luò)后才能流暢使用税稼。" preferredStyle:UIAlertControllerStyleAlert];
//UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {}];
UIAlertAction *sure = [UIAlertAction actionWithTitle:@"設(shè)置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
//[alertVC addAction:cancel];
[alertVC addAction:sure];
[self presentViewController:alertVC animated:YES completion:nil];
}
};
}
鏈接網(wǎng)絡(luò).png