iOS源码解析iOS Developer

iOS 10 联网权限

2016-11-06  本文已影响363人  cb6a1e2768d1

引入头文件 @import CoreTelephony;

检测应用中是否有联网权限

CTCellularData *cellularData = [[CTCellularData alloc]init];
cellularData.cellularDataRestrictionDidUpdateNotifier =  ^(CTCellularDataRestrictedState state){
  //获取联网状态
  switch (state) {
      case kCTCellularDataRestricted:
          NSLog(@"Restricrted");
          break;
      case kCTCellularDataNotRestricted:
          NSLog(@"Not Restricted");
          break;
      case kCTCellularDataRestrictedStateUnknown:
          NSLog(@"Unknown");
          break;
      default:
          break;
  };
};

查询应用是否有联网功能

CTCellularData *cellularData = [[CTCellularData alloc]init];
CTCellularDataRestrictedState state = cellularData.restrictedState;
 switch (state) {
  case kCTCellularDataRestricted:
      NSLog(@"Restricrted");
      break;
  case kCTCellularDataNotRestricted:
      NSLog(@"Not Restricted");
      break;
  case kCTCellularDataRestrictedStateUnknown:
      NSLog(@"Unknown");
      break;
  default:
      break;
}

不知道你们觉不觉得,升级了iOS10之后,很多应用下载完打开,都弹出很多权限申请,非常觉得不爽,而且有时候联网这个申请会被其它权限申请给覆盖了,每次都要去设置里面打开,用户体验一点都不好。

前往 设置

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
上一篇下一篇

猜你喜欢

热点阅读