Skip to content

Commit

Permalink
APP合规整改:权限管理页面默认不弹权限弹框,相机权限描述提示语言修改
Browse files Browse the repository at this point in the history
Tapd: http://tapd.oa.com/NEW_IOT/prong/stories/view/1020393192871147007
Change-Id: Id23a3cde43af499e3b1e81280f47f8d45a99e843
  • Loading branch information
ccharlesren committed Jan 26, 2022
1 parent aa8a84c commit eb7f264
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 15 deletions.
134 changes: 123 additions & 11 deletions Source/LinkApp/Classes/Module/Mine/Controller/TIoTAuthentationVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
#import <AVFoundation/AVFoundation.h>
#import "TIoTCoreUtil.h"

@interface TIoTAuthentationVC ()<UITableViewDelegate, UITableViewDataSource, CBCentralManagerDelegate>
@interface TIoTAuthentationVC ()<UITableViewDelegate, UITableViewDataSource, CBCentralManagerDelegate,CLLocationManagerDelegate>
@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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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推送
/**是否开启推送*/
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)id<TIoTUserInfomationTableViewCellDelegate>delegate;
@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ NSBluetoothAlwaysUsageDescription = "为了便于您访问蓝牙设备,因此
NSBluetoothPeripheralUsageDescription = "为了便于您访问蓝牙设备,因此腾讯连连需获取蓝牙权限";
NSCameraUsageDescription = "为了便于您扫码添加设备、使用拍照功能和视频功能,因此腾讯连连需获取相机权限";
NSLocationWhenInUseUsageDescription = "为了在设备配网时能获取当前位置的WiFi信息,我们需要您开通位置权限;如果您拒绝开通位置权限的,我们将不能获取当前的WIFI信息,可能导致设备配网功能无法使用。如果您需要获取更精准的天气服务,可以选择开通位置权限;如果您拒绝开通位置权限,您也可以通过自行搜索位置实现该位置的天气服务";
NSPhotoLibraryUsageDescription = "为了便于您可选择本地图片以更换头像,因此腾讯连连需获取相册权限";
NSPhotoLibraryUsageDescription = "为了便于您可选择本地图片以更换头像和识别二维码添加设备,因此腾讯连连需获取相册权限";
NSMicrophoneUsageDescription = "为了使用设备的实时语音/通话功能,因此腾讯连连需获取麦克风权限";
//NSLocalNetworkUsageDescription = "获取组播权限,用于智能产品配网:";
5 changes: 5 additions & 0 deletions Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, copy, nullable) NSString *addDeviceNumber; //用户首次进入APP,添加设备数量

/**
进入权限管理页面,是否修改过蓝牙权限
*/
@property (nonatomic, copy, nullable) NSString *isChangeBluetoothAuth; //是否修改过蓝牙权限

/**
地图搜索页面,搜索历史记录
*/
Expand Down
15 changes: 15 additions & 0 deletions Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ @implementation TIoTCoreUserManage
@synthesize firmwareUpdate = _firmwareUpdate;
@synthesize isRreshDeviceList = _isRreshDeviceList;
@synthesize isVersionUpdateView = _isVersionUpdateView;
@synthesize isChangeBluetoothAuth = _isChangeBluetoothAuth;

+(instancetype)shared{
static TIoTCoreUserManage *_instance = nil;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (BOOL)requestMediaAuthorization:(AVMediaType)mediaType;

/**
用户是否授权摄像头和麦克风权限(无弹框)
*/
+ (BOOL)userAccessMediaAuthorization:(AVMediaType)mediaType;
@end

NS_ASSUME_NONNULL_END
17 changes: 17 additions & 0 deletions Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit eb7f264

Please sign in to comment.