Skip to content

Commit eb7f264

Browse files
author
ccharlesren
committed
APP合规整改:权限管理页面默认不弹权限弹框,相机权限描述提示语言修改
Tapd: http://tapd.oa.com/NEW_IOT/prong/stories/view/1020393192871147007 Change-Id: Id23a3cde43af499e3b1e81280f47f8d45a99e843
1 parent aa8a84c commit eb7f264

File tree

9 files changed

+168
-15
lines changed

9 files changed

+168
-15
lines changed

Source/LinkApp/Classes/Module/Mine/Controller/TIoTAuthentationVC.m

Lines changed: 123 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
#import <AVFoundation/AVFoundation.h>
1111
#import "TIoTCoreUtil.h"
1212

13-
@interface TIoTAuthentationVC ()<UITableViewDelegate, UITableViewDataSource, CBCentralManagerDelegate>
13+
@interface TIoTAuthentationVC ()<UITableViewDelegate, UITableViewDataSource, CBCentralManagerDelegate,CLLocationManagerDelegate>
1414
@property (nonatomic, strong) UITableView *tableView;
1515
@property (nonatomic, copy) NSMutableArray *dataArr;
1616
@property (nonatomic, strong) CBCentralManager *centralManager; //判断蓝牙是否开启
1717
/// 蓝牙是否可用
1818
@property (nonatomic, assign) BOOL bluetoothAvailable;
19+
20+
@property (nonatomic, strong) CLLocationManager *locationManager;
21+
@property (nonatomic, assign) BOOL locationAvailable; //地图是否可用
1922
@end
2023

2124
@implementation TIoTAuthentationVC
@@ -33,7 +36,17 @@ - (void)viewDidLoad {
3336
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationwillenterforegound) name:UIApplicationWillEnterForegroundNotification object:nil];
3437

3538
//判断蓝牙是否开启
36-
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
39+
if ([[TIoTCoreUserManage shared].isChangeBluetoothAuth isEqualToString:@"1"]) {
40+
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
41+
self.bluetoothAvailable = YES;
42+
}else {
43+
if (![NSString isNullOrNilWithObject:[TIoTCoreUserManage shared].isChangeBluetoothAuth]) {
44+
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
45+
}else {
46+
self.bluetoothAvailable = NO;
47+
}
48+
49+
}
3750
}
3851

3952
- (void)applicationwillenterforegound
@@ -93,13 +106,75 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
93106
cell.arrowSwitch.on = self.bluetoothAvailable;
94107
}
95108

96-
cell.authSwitch = ^(BOOL open) {
97-
98-
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
99-
if ([[UIApplication sharedApplication] canOpenURL:url]){
100-
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
101-
}
109+
cell.authSwitch = ^(BOOL open,UISwitch *switchControl) {
102110

111+
if (indexPath.section == 0) {
112+
[self jumpSetting];
113+
114+
}else if (indexPath.section == 1) {
115+
CLAuthorizationStatus CLstatus = [CLLocationManager authorizationStatus];
116+
if (CLstatus == kCLAuthorizationStatusNotDetermined) {
117+
self.locationManager = [[CLLocationManager alloc] init];
118+
self.locationManager.delegate = self;
119+
}else {
120+
[self jumpSetting];
121+
}
122+
123+
}else if (indexPath.section == 2) {
124+
if ([self getMediaNotDetermStatusWithType:AVMediaTypeVideo]) {
125+
126+
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo
127+
completionHandler:^(BOOL granted) {
128+
dispatch_async(dispatch_get_main_queue(), ^{
129+
if (granted) {
130+
//同意授权
131+
switchControl.on = YES;
132+
} else {
133+
//拒绝授权
134+
switchControl.on = NO;
135+
}
136+
});
137+
}];
138+
139+
}else {
140+
[self jumpSetting];
141+
}
142+
}else if (indexPath.section == 3) {
143+
if ([self getMediaNotDetermStatusWithType:AVMediaTypeAudio]) {
144+
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio
145+
completionHandler:^(BOOL granted) {
146+
dispatch_async(dispatch_get_main_queue(), ^{
147+
if (granted) {
148+
//同意授权
149+
switchControl.on = YES;
150+
} else {
151+
//拒绝授权
152+
switchControl.on = NO;
153+
}
154+
});
155+
}];
156+
}else {
157+
[self jumpSetting];
158+
}
159+
}else if (indexPath.section == 4) {
160+
if (self.centralManager.state == CBManagerStateUnauthorized) {
161+
//判断蓝牙是否开启
162+
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
163+
if (![NSString isNullOrNilWithObject:[TIoTCoreUserManage shared].isChangeBluetoothAuth]) {
164+
[self jumpSetting];
165+
}
166+
}else {
167+
168+
if ([NSString isNullOrNilWithObject:[TIoTCoreUserManage shared].isChangeBluetoothAuth]) {
169+
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
170+
}else {
171+
if ([[TIoTCoreUserManage shared].isChangeBluetoothAuth isEqualToString:@"0"]) {
172+
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
173+
}
174+
[self jumpSetting];
175+
}
176+
}
177+
}
103178
};
104179
return cell;
105180
}
@@ -143,6 +218,22 @@ - (NSMutableArray *)dataArr{
143218
return _dataArr;
144219
}
145220

221+
//判断是否麦克风和摄像头请求授权
222+
- (BOOL)getMediaNotDetermStatusWithType:(AVMediaType)mediaType {
223+
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
224+
if (authStatus == AVAuthorizationStatusNotDetermined) {
225+
return YES;
226+
}else {
227+
return NO;
228+
}
229+
}
230+
231+
- (void)jumpSetting {
232+
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
233+
if ([[UIApplication sharedApplication] canOpenURL:url]){
234+
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
235+
}
236+
}
146237

147238
#pragma mark - 是否开启APP推送
148239
/**是否开启推送*/
@@ -196,7 +287,7 @@ - (BOOL)locationAuthority {
196287
if (isLocation) {
197288

198289
CLAuthorizationStatus CLstatus = [CLLocationManager authorizationStatus];
199-
if (CLstatus == kCLAuthorizationStatusDenied || CLstatus == kCLAuthorizationStatusDenied) {
290+
if (CLstatus == kCLAuthorizationStatusDenied || CLstatus == kCLAuthorizationStatusDenied || CLstatus == kCLAuthorizationStatusNotDetermined) {
200291
return NO;
201292
}
202293

@@ -207,25 +298,30 @@ - (BOOL)locationAuthority {
207298
}
208299

209300
- (BOOL)audioAuthority:(AVMediaType)type {
210-
return [TIoTCoreUtil requestMediaAuthorization:type];
301+
// return [TIoTCoreUtil requestMediaAuthorization:type];
302+
return [TIoTCoreUtil userAccessMediaAuthorization:type];
211303
}
212304

213305
#pragma mark - 判断蓝牙是否开启代理
214306
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
215307
switch (central.state) {
216308
case CBManagerStatePoweredOn:
309+
[TIoTCoreUserManage shared].isChangeBluetoothAuth = @"1";
217310
self.bluetoothAvailable = true; break; //NSLog(@"蓝牙开启且可用");
218311
case CBManagerStateUnknown:
312+
[TIoTCoreUserManage shared].isChangeBluetoothAuth = @"0";
219313
self.bluetoothAvailable = false; break; //NSLog(@"手机没有识别到蓝牙,请检查手机。");
220314
case CBManagerStateResetting:
315+
[TIoTCoreUserManage shared].isChangeBluetoothAuth = @"1";
221316
self.bluetoothAvailable = false; break; //NSLog(@"手机蓝牙已断开连接,重置中。");
222317
case CBManagerStateUnsupported:
223318
self.bluetoothAvailable = false; break; //NSLog(@"手机不支持蓝牙功能,请更换手机。");
224319
case CBManagerStatePoweredOff:
225-
226320
[self customAlertOpenBluetooth];
321+
[TIoTCoreUserManage shared].isChangeBluetoothAuth = @"0";
227322
self.bluetoothAvailable = false; break; //NSLog(@"手机蓝牙功能关闭,请前往设置打开蓝牙及控制中心打开蓝牙。");
228323
case CBManagerStateUnauthorized:
324+
[TIoTCoreUserManage shared].isChangeBluetoothAuth = @"0";
229325
self.bluetoothAvailable = false; break; //NSLog(@"手机蓝牙功能没有权限,请前往设置。");
230326
default: break;
231327
}
@@ -250,10 +346,26 @@ - (void)customAlertOpenBluetooth {
250346
[alertC addAction:alertCancel];
251347

252348
UIAlertAction *alertConfirm = [UIAlertAction actionWithTitle:NSLocalizedString(@"confirm", @"确定") style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
349+
[self jumpSetting];
253350
}];
254351
[alertC addAction:alertConfirm];
255352

256353
[self presentViewController:alertC animated:YES completion:nil];
257354
}
258355

356+
#pragma mark CLLocationManagerDelegate
357+
358+
- (void)locationManagerDidChangeAuthorization:(CLLocationManager *)manager API_AVAILABLE(ios(14.0), macos(11.0), watchos(7.0), tvos(14.0)) {
359+
CLAuthorizationStatus status = [manager authorizationStatus];
360+
if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorizedAlways) {
361+
self.locationAvailable = YES;
362+
}else if (status == kCLAuthorizationStatusNotDetermined) {
363+
self.locationAvailable = NO;
364+
[manager requestWhenInUseAuthorization];
365+
}else {
366+
//提示语弹框
367+
self.locationAvailable = NO;
368+
}
369+
[self.tableView reloadData];
370+
}
259371
@end

Source/LinkApp/Classes/Module/Mine/View/TIoTUserInfomationTableViewCell.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static NSString * const ID = @"TIoTUserInfomationTableViewCell";
2121
@property (nonatomic, copy) NSDictionary *dic;
2222

2323
@property (nonatomic, strong) UISwitch *arrowSwitch;
24-
@property (nonatomic) void (^authSwitch)(BOOL open);
24+
@property (nonatomic) void (^authSwitch)(BOOL open,UISwitch *switchControl);
2525
@property (nonatomic, weak)id<TIoTUserInfomationTableViewCellDelegate>delegate;
2626
@end
2727

Source/LinkApp/Classes/Module/Mine/View/TIoTUserInfomationTableViewCell.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
156156

157157
- (void)openAuth:(UISwitch *)sender {
158158
if (self.authSwitch) {
159-
self.authSwitch(sender.on);
159+
self.authSwitch(sender.on,self.arrowSwitch);
160160
}
161161
}
162162
@end

Source/LinkApp/Supporting Files/Resource/en.lproj/InfoPlist.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ NSBluetoothAlwaysUsageDescription = "Turn on Bluetooth to scan for hardware";
88
NSBluetoothPeripheralUsageDescription = "Turn on Bluetooth to scan for hardware";
99
NSCameraUsageDescription = "Obtain camera permission to scan the QR code and video function of the device";
1010
NSLocationWhenInUseUsageDescription = "User obtains location information";
11-
NSPhotoLibraryUsageDescription = "Obtain the permission of the album to identify the local QR code";
11+
NSPhotoLibraryUsageDescription = "Obtain the permission of the album to identify the local QR code and change the avatar";
1212
NSMicrophoneUsageDescription = "Obtain microphone permission to use the real-time voice and call functions of the device";

Source/LinkApp/Supporting Files/Resource/zh-Hans.lproj/InfoPlist.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ NSBluetoothAlwaysUsageDescription = "为了便于您访问蓝牙设备,因此
88
NSBluetoothPeripheralUsageDescription = "为了便于您访问蓝牙设备,因此腾讯连连需获取蓝牙权限";
99
NSCameraUsageDescription = "为了便于您扫码添加设备、使用拍照功能和视频功能,因此腾讯连连需获取相机权限";
1010
NSLocationWhenInUseUsageDescription = "为了在设备配网时能获取当前位置的WiFi信息,我们需要您开通位置权限;如果您拒绝开通位置权限的,我们将不能获取当前的WIFI信息,可能导致设备配网功能无法使用。如果您需要获取更精准的天气服务,可以选择开通位置权限;如果您拒绝开通位置权限,您也可以通过自行搜索位置实现该位置的天气服务";
11-
NSPhotoLibraryUsageDescription = "为了便于您可选择本地图片以更换头像,因此腾讯连连需获取相册权限";
11+
NSPhotoLibraryUsageDescription = "为了便于您可选择本地图片以更换头像和识别二维码添加设备,因此腾讯连连需获取相册权限";
1212
NSMicrophoneUsageDescription = "为了使用设备的实时语音/通话功能,因此腾讯连连需获取麦克风权限";
1313
//NSLocalNetworkUsageDescription = "获取组播权限,用于智能产品配网:";

Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ NS_ASSUME_NONNULL_BEGIN
105105

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

108+
/**
109+
进入权限管理页面,是否修改过蓝牙权限
110+
*/
111+
@property (nonatomic, copy, nullable) NSString *isChangeBluetoothAuth; //是否修改过蓝牙权限
112+
108113
/**
109114
地图搜索页面,搜索历史记录
110115
*/

Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUserManage.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ @implementation TIoTCoreUserManage
5555
@synthesize firmwareUpdate = _firmwareUpdate;
5656
@synthesize isRreshDeviceList = _isRreshDeviceList;
5757
@synthesize isVersionUpdateView = _isVersionUpdateView;
58+
@synthesize isChangeBluetoothAuth = _isChangeBluetoothAuth;
5859

5960
+(instancetype)shared{
6061
static TIoTCoreUserManage *_instance = nil;
@@ -527,6 +528,20 @@ - (void)setSignIn_Email_Address:(NSString *)signIn_Email_Address {
527528
[[NSUserDefaults standardUserDefaults] setValue:signIn_Email_Address forKey:@"signIn_Email_Address"];
528529
}
529530

531+
#pragma mark - 是否更改过蓝牙权限
532+
533+
- (NSString *)isChangeBluetoothAuth {
534+
if (!_isChangeBluetoothAuth) {
535+
_isChangeBluetoothAuth = [[NSUserDefaults standardUserDefaults] valueForKey:@"is_ChangeBluetooth_Auth"];
536+
}
537+
return _isChangeBluetoothAuth;
538+
}
539+
540+
- (void)setIsChangeBluetoothAuth:(NSString *)isChangeBluetoothAuth {
541+
_isChangeBluetoothAuth = isChangeBluetoothAuth;
542+
[[NSUserDefaults standardUserDefaults] setValue:isChangeBluetoothAuth forKey:@"is_ChangeBluetooth_Auth"];
543+
}
544+
530545
#pragma mark - 地图搜索
531546
- (void)setSearchHistoryArray:(NSMutableArray *)searchHistoryArray {
532547
_searchHistoryArray = searchHistoryArray;

Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ NS_ASSUME_NONNULL_BEGIN
7272
*/
7373
+ (BOOL)requestMediaAuthorization:(AVMediaType)mediaType;
7474

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

7781
NS_ASSUME_NONNULL_END

Source/SDK/LinkCore/QCFoundation/Other/TIoTCoreUtil.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,21 @@ + (BOOL)requestMediaAuthorization:(AVMediaType)mediaType {
443443
return isAccess;
444444
}
445445

446+
/**
447+
获取摄像头和麦克风权限状态(无弹框)
448+
*/
449+
+ (BOOL)userAccessMediaAuthorization:(AVMediaType)mediaType; {
450+
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
451+
BOOL isAccess = NO;
452+
if (authStatus == AVAuthorizationStatusNotDetermined) {
453+
isAccess = NO;
454+
} else if (authStatus == AVAuthorizationStatusDenied || authStatus == AVAuthorizationStatusRestricted) {
455+
//拒绝授权
456+
isAccess = NO;
457+
} else if (authStatus == AVAuthorizationStatusAuthorized) {
458+
//同意授权
459+
isAccess = YES;
460+
}
461+
return isAccess;
462+
}
446463
@end

0 commit comments

Comments
 (0)