diff --git a/Source/LinkApp/Classes/Module/Mine/Controller/TIoTAuthentationVC.m b/Source/LinkApp/Classes/Module/Mine/Controller/TIoTAuthentationVC.m index e833a72a5..f57e3c91c 100644 --- a/Source/LinkApp/Classes/Module/Mine/Controller/TIoTAuthentationVC.m +++ b/Source/LinkApp/Classes/Module/Mine/Controller/TIoTAuthentationVC.m @@ -10,12 +10,15 @@ #import #import "TIoTCoreUtil.h" -@interface TIoTAuthentationVC () +@interface TIoTAuthentationVC () @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, copy) NSMutableArray *dataArr; @property (nonatomic, strong) CBCentralManager *centralManager; //判断蓝牙是否开启 /// 蓝牙是否可用 @property (nonatomic, assign) BOOL bluetoothAvailable; + +@property (nonatomic, strong) CLLocationManager *locationManager; +@property (nonatomic, assign) BOOL locationAvailable; //地图是否可用 @end @implementation TIoTAuthentationVC @@ -33,7 +36,17 @@ - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationwillenterforegound) name:UIApplicationWillEnterForegroundNotification object:nil]; //判断蓝牙是否开启 - self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil]; + if ([[TIoTCoreUserManage shared].isChangeBluetoothAuth isEqualToString:@"1"]) { + self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil]; + self.bluetoothAvailable = YES; + }else { + if (![NSString isNullOrNilWithObject:[TIoTCoreUserManage shared].isChangeBluetoothAuth]) { + self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil]; + }else { + self.bluetoothAvailable = NO; + } + + } } - (void)applicationwillenterforegound @@ -93,13 +106,75 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.arrowSwitch.on = self.bluetoothAvailable; } - cell.authSwitch = ^(BOOL open) { - - NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; - if ([[UIApplication sharedApplication] canOpenURL:url]){ - [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; - } + cell.authSwitch = ^(BOOL open,UISwitch *switchControl) { + if (indexPath.section == 0) { + [self jumpSetting]; + + }else if (indexPath.section == 1) { + CLAuthorizationStatus CLstatus = [CLLocationManager authorizationStatus]; + if (CLstatus == kCLAuthorizationStatusNotDetermined) { + self.locationManager = [[CLLocationManager alloc] init]; + self.locationManager.delegate = self; + }else { + [self jumpSetting]; + } + + }else if (indexPath.section == 2) { + if ([self getMediaNotDetermStatusWithType:AVMediaTypeVideo]) { + + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo + completionHandler:^(BOOL granted) { + dispatch_async(dispatch_get_main_queue(), ^{ + if (granted) { + //同意授权 + switchControl.on = YES; + } else { + //拒绝授权 + switchControl.on = NO; + } + }); + }]; + + }else { + [self jumpSetting]; + } + }else if (indexPath.section == 3) { + if ([self getMediaNotDetermStatusWithType:AVMediaTypeAudio]) { + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio + completionHandler:^(BOOL granted) { + dispatch_async(dispatch_get_main_queue(), ^{ + if (granted) { + //同意授权 + switchControl.on = YES; + } else { + //拒绝授权 + switchControl.on = NO; + } + }); + }]; + }else { + [self jumpSetting]; + } + }else if (indexPath.section == 4) { + if (self.centralManager.state == CBManagerStateUnauthorized) { + //判断蓝牙是否开启 + self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil]; + if (![NSString isNullOrNilWithObject:[TIoTCoreUserManage shared].isChangeBluetoothAuth]) { + [self jumpSetting]; + } + }else { + + if ([NSString isNullOrNilWithObject:[TIoTCoreUserManage shared].isChangeBluetoothAuth]) { + self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil]; + }else { + if ([[TIoTCoreUserManage shared].isChangeBluetoothAuth isEqualToString:@"0"]) { + self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil]; + } + [self jumpSetting]; + } + } + } }; return cell; } @@ -143,6 +218,22 @@ - (NSMutableArray *)dataArr{ return _dataArr; } +//判断是否麦克风和摄像头请求授权 +- (BOOL)getMediaNotDetermStatusWithType:(AVMediaType)mediaType { + AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; + if (authStatus == AVAuthorizationStatusNotDetermined) { + return YES; + }else { + return NO; + } +} + +- (void)jumpSetting { + NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; + if ([[UIApplication sharedApplication] canOpenURL:url]){ + [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; + } +} #pragma mark - 是否开启APP推送 /**是否开启推送*/ @@ -196,7 +287,7 @@ - (BOOL)locationAuthority { if (isLocation) { CLAuthorizationStatus CLstatus = [CLLocationManager authorizationStatus]; - if (CLstatus == kCLAuthorizationStatusDenied || CLstatus == kCLAuthorizationStatusDenied) { + if (CLstatus == kCLAuthorizationStatusDenied || CLstatus == kCLAuthorizationStatusDenied || CLstatus == kCLAuthorizationStatusNotDetermined) { return NO; } @@ -207,25 +298,30 @@ - (BOOL)locationAuthority { } - (BOOL)audioAuthority:(AVMediaType)type { - return [TIoTCoreUtil requestMediaAuthorization:type]; +// return [TIoTCoreUtil requestMediaAuthorization:type]; + return [TIoTCoreUtil userAccessMediaAuthorization:type]; } #pragma mark - 判断蓝牙是否开启代理 - (void)centralManagerDidUpdateState:(CBCentralManager *)central { switch (central.state) { case CBManagerStatePoweredOn: + [TIoTCoreUserManage shared].isChangeBluetoothAuth = @"1"; self.bluetoothAvailable = true; break; //NSLog(@"蓝牙开启且可用"); case CBManagerStateUnknown: + [TIoTCoreUserManage shared].isChangeBluetoothAuth = @"0"; self.bluetoothAvailable = false; break; //NSLog(@"手机没有识别到蓝牙,请检查手机。"); case CBManagerStateResetting: + [TIoTCoreUserManage shared].isChangeBluetoothAuth = @"1"; self.bluetoothAvailable = false; break; //NSLog(@"手机蓝牙已断开连接,重置中。"); case CBManagerStateUnsupported: self.bluetoothAvailable = false; break; //NSLog(@"手机不支持蓝牙功能,请更换手机。"); case CBManagerStatePoweredOff: - [self customAlertOpenBluetooth]; + [TIoTCoreUserManage shared].isChangeBluetoothAuth = @"0"; self.bluetoothAvailable = false; break; //NSLog(@"手机蓝牙功能关闭,请前往设置打开蓝牙及控制中心打开蓝牙。"); case CBManagerStateUnauthorized: + [TIoTCoreUserManage shared].isChangeBluetoothAuth = @"0"; self.bluetoothAvailable = false; break; //NSLog(@"手机蓝牙功能没有权限,请前往设置。"); default: break; } @@ -250,10 +346,26 @@ - (void)customAlertOpenBluetooth { [alertC addAction:alertCancel]; UIAlertAction *alertConfirm = [UIAlertAction actionWithTitle:NSLocalizedString(@"confirm", @"确定") style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { + [self jumpSetting]; }]; [alertC addAction:alertConfirm]; [self presentViewController:alertC animated:YES completion:nil]; } +#pragma mark CLLocationManagerDelegate + +- (void)locationManagerDidChangeAuthorization:(CLLocationManager *)manager API_AVAILABLE(ios(14.0), macos(11.0), watchos(7.0), tvos(14.0)) { + CLAuthorizationStatus status = [manager authorizationStatus]; + if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorizedAlways) { + self.locationAvailable = YES; + }else if (status == kCLAuthorizationStatusNotDetermined) { + self.locationAvailable = NO; + [manager requestWhenInUseAuthorization]; + }else { + //提示语弹框 + self.locationAvailable = NO; + } + [self.tableView reloadData]; +} @end diff --git a/Source/LinkApp/Classes/Module/Mine/View/TIoTUserInfomationTableViewCell.h b/Source/LinkApp/Classes/Module/Mine/View/TIoTUserInfomationTableViewCell.h index 21d29c05e..bdcd437a7 100644 --- a/Source/LinkApp/Classes/Module/Mine/View/TIoTUserInfomationTableViewCell.h +++ b/Source/LinkApp/Classes/Module/Mine/View/TIoTUserInfomationTableViewCell.h @@ -21,7 +21,7 @@ static NSString * const ID = @"TIoTUserInfomationTableViewCell"; @property (nonatomic, copy) NSDictionary *dic; @property (nonatomic, strong) UISwitch *arrowSwitch; -@property (nonatomic) void (^authSwitch)(BOOL open); +@property (nonatomic) void (^authSwitch)(BOOL open,UISwitch *switchControl); @property (nonatomic, weak)iddelegate; @end diff --git a/Source/LinkApp/Classes/Module/Mine/View/TIoTUserInfomationTableViewCell.m b/Source/LinkApp/Classes/Module/Mine/View/TIoTUserInfomationTableViewCell.m index d6c7b08fc..8188e0ca1 100644 --- a/Source/LinkApp/Classes/Module/Mine/View/TIoTUserInfomationTableViewCell.m +++ b/Source/LinkApp/Classes/Module/Mine/View/TIoTUserInfomationTableViewCell.m @@ -156,7 +156,7 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated { - (void)openAuth:(UISwitch *)sender { if (self.authSwitch) { - self.authSwitch(sender.on); + self.authSwitch(sender.on,self.arrowSwitch); } } @end diff --git a/Source/LinkApp/Supporting Files/Resource/en.lproj/InfoPlist.strings b/Source/LinkApp/Supporting Files/Resource/en.lproj/InfoPlist.strings index 03a90c857..003090c66 100644 --- a/Source/LinkApp/Supporting Files/Resource/en.lproj/InfoPlist.strings +++ b/Source/LinkApp/Supporting Files/Resource/en.lproj/InfoPlist.strings @@ -8,5 +8,5 @@ NSBluetoothAlwaysUsageDescription = "Turn on Bluetooth to scan for hardware"; NSBluetoothPeripheralUsageDescription = "Turn on Bluetooth to scan for hardware"; NSCameraUsageDescription = "Obtain camera permission to scan the QR code and video function of the device"; NSLocationWhenInUseUsageDescription = "User obtains location information"; -NSPhotoLibraryUsageDescription = "Obtain the permission of the album to identify the local QR code"; +NSPhotoLibraryUsageDescription = "Obtain the permission of the album to identify the local QR code and change the avatar"; NSMicrophoneUsageDescription = "Obtain microphone permission to use the real-time voice and call functions of the device"; diff --git a/Source/LinkApp/Supporting Files/Resource/zh-Hans.lproj/InfoPlist.strings b/Source/LinkApp/Supporting Files/Resource/zh-Hans.lproj/InfoPlist.strings index da3511c74..e0f85e62c 100644 --- a/Source/LinkApp/Supporting Files/Resource/zh-Hans.lproj/InfoPlist.strings +++ b/Source/LinkApp/Supporting Files/Resource/zh-Hans.lproj/InfoPlist.strings @@ -8,6 +8,6 @@ NSBluetoothAlwaysUsageDescription = "为了便于您访问蓝牙设备,因此 NSBluetoothPeripheralUsageDescription = "为了便于您访问蓝牙设备,因此腾讯连连需获取蓝牙权限"; NSCameraUsageDescription = "为了便于您扫码添加设备、使用拍照功能和视频功能,因此腾讯连连需获取相机权限"; NSLocationWhenInUseUsageDescription = "为了在设备配网时能获取当前位置的WiFi信息,我们需要您开通位置权限;如果您拒绝开通位置权限的,我们将不能获取当前的WIFI信息,可能导致设备配网功能无法使用。如果您需要获取更精准的天气服务,可以选择开通位置权限;如果您拒绝开通位置权限,您也可以通过自行搜索位置实现该位置的天气服务"; -NSPhotoLibraryUsageDescription = "为了便于您可选择本地图片以更换头像,因此腾讯连连需获取相册权限"; +NSPhotoLibraryUsageDescription = "为了便于您可选择本地图片以更换头像和识别二维码添加设备,因此腾讯连连需获取相册权限"; NSMicrophoneUsageDescription = "为了使用设备的实时语音/通话功能,因此腾讯连连需获取麦克风权限"; //NSLocalNetworkUsageDescription = "获取组播权限,用于智能产品配网:"; diff --git a/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.h b/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.h index 75e9dc12a..9eb9d77f4 100644 --- a/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.h +++ b/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.h @@ -105,6 +105,11 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, nullable) NSString *addDeviceNumber; //用户首次进入APP,添加设备数量 +/** + 进入权限管理页面,是否修改过蓝牙权限 + */ +@property (nonatomic, copy, nullable) NSString *isChangeBluetoothAuth; //是否修改过蓝牙权限 + /** 地图搜索页面,搜索历史记录 */ diff --git a/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.m b/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.m index c1a108dc1..3e9a63e0c 100644 --- a/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.m +++ b/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.m @@ -55,6 +55,7 @@ @implementation TIoTCoreUserManage @synthesize firmwareUpdate = _firmwareUpdate; @synthesize isRreshDeviceList = _isRreshDeviceList; @synthesize isVersionUpdateView = _isVersionUpdateView; +@synthesize isChangeBluetoothAuth = _isChangeBluetoothAuth; +(instancetype)shared{ static TIoTCoreUserManage *_instance = nil; @@ -527,6 +528,20 @@ - (void)setSignIn_Email_Address:(NSString *)signIn_Email_Address { [[NSUserDefaults standardUserDefaults] setValue:signIn_Email_Address forKey:@"signIn_Email_Address"]; } +#pragma mark - 是否更改过蓝牙权限 + +- (NSString *)isChangeBluetoothAuth { + if (!_isChangeBluetoothAuth) { + _isChangeBluetoothAuth = [[NSUserDefaults standardUserDefaults] valueForKey:@"is_ChangeBluetooth_Auth"]; + } + return _isChangeBluetoothAuth; +} + +- (void)setIsChangeBluetoothAuth:(NSString *)isChangeBluetoothAuth { + _isChangeBluetoothAuth = isChangeBluetoothAuth; + [[NSUserDefaults standardUserDefaults] setValue:isChangeBluetoothAuth forKey:@"is_ChangeBluetooth_Auth"]; +} + #pragma mark - 地图搜索 - (void)setSearchHistoryArray:(NSMutableArray *)searchHistoryArray { _searchHistoryArray = searchHistoryArray; diff --git a/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.h b/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.h index 254a6cd02..ee8c4e402 100644 --- a/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.h +++ b/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.h @@ -72,6 +72,10 @@ NS_ASSUME_NONNULL_BEGIN */ + (BOOL)requestMediaAuthorization:(AVMediaType)mediaType; +/** + 用户是否授权摄像头和麦克风权限(无弹框) + */ ++ (BOOL)userAccessMediaAuthorization:(AVMediaType)mediaType; @end NS_ASSUME_NONNULL_END diff --git a/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.m b/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.m index 79e420572..24852e957 100644 --- a/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.m +++ b/Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.m @@ -443,4 +443,21 @@ + (BOOL)requestMediaAuthorization:(AVMediaType)mediaType { return isAccess; } +/** + 获取摄像头和麦克风权限状态(无弹框) + */ ++ (BOOL)userAccessMediaAuthorization:(AVMediaType)mediaType; { + AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; + BOOL isAccess = NO; + if (authStatus == AVAuthorizationStatusNotDetermined) { + isAccess = NO; + } else if (authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusRestricted) { + //拒绝授权 + isAccess = NO; + } else if (authStatus == AVAuthorizationStatusAuthorized) { + //同意授权 + isAccess = YES; + } + return isAccess; +} @end