- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要在我的应用程序中访问照片和 map 。所以我在 plist 文件中添加了相应的功能。但是我需要检查请求是否被允许或拒绝。我不知道该怎么做,请建议我这个。
最佳答案
您必须明确检查不同类型的权限,例如图像/视频、位置、联系人列表等。
图片/视频/音频/文档等
NSString *mediaType = AVMediaTypeVideo;
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == AVAuthorizationStatusAuthorized)
{
// do your logic
} else if(authStatus == AVAuthorizationStatusDenied)
{
// denied
[self showSettingsAlert:@"Previously you have denied"];
} else if(authStatus == AVAuthorizationStatusRestricted)
{
// restricted, normally won't happen
[self showSettingsAlert:@"You have revoke"];
} else if(authStatus == AVAuthorizationStatusNotDetermined)
{
// not determined?!
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted)
{
if(granted)
{
[self openVideoPicker:buttonIndex];
} else
{
[self showSettingsAlert:@"You have denied"];
}
}];
} else
{
[self showSettingsAlert:@"You have revoke"];
}
只需根据您的要求更改 AVMediaTypes。
手机联系人列表
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted)
{
//Show Alert Access Denied
return;
}
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error)
{
// make sure the user granted us access
if (!granted)
{
dispatch_async(dispatch_get_main_queue(), ^{
//Show Alert Access Denied
return;
}
BOOL success = [store enumerateContactsWithFetchRequest:request error:&fetchError usingBlock:^(CNContact *contact, BOOL *stop)
{
// build array of contacts
NSMutableArray *contacts = [NSMutableArray array];
NSError *fetchError;
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[CNContactIdentifierKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName], CNContactPhoneNumbersKey, CNContactGivenNameKey, CNContactFamilyNameKey]];
[contacts addObject:contact];
}];
if (!success)
{
[UIUtil showWarningAlert:fetchError.localizedDescription onController:self];
return;
}
将此代码放入将处理此类权限验证的函数中。
对于位置,您必须实现CLLocationManagerDelegate,这两个函数将为您提供位置信息。
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
currentLocation = [locations objectAtIndex:0];
[locationManager stopUpdatingLocation];
latitude = [NSString stringWithFormat:@"%f", currentLocation.coordinate.latitude];
longitude = [NSString stringWithFormat:@"%f", currentLocation.coordinate.longitude];
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
if (error.domain == kCLErrorDomain && error.code == kCLErrorDenied)
{
[locationManager stopUpdatingLocation];
[self showSettingsAlert:@"You have denied Location Permission"];
}
}
不要忘记为这些代码导入适当的包。
关于ios - 如何检查 ios 中的 RequestPermissions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49610496/
运行时权限对话框在 Android 6.0 或更高版本中显示,因此在 API 级别 23 中添加的 Activity.requestPermissions(...) 是有意义的。 但是为什么还有一个(
当我的Activity来电ActivityCompat.requestPermissions ,不出现 UI 对话框。 ActivityCompat.requestPermissions(HomeAc
问题... 我正在尝试在 Android Marshmallow 中实现运行时权限,同时保持向后兼容性。我以前已经成功完成过此操作,我不确定这次有什么不同。我已经在物理 Note 5(运行 Mallo
我发现了很多具有相同威胁的相似主题,但我仍然找不到解决我的问题的方法。我写这段代码是为了向应用程序授予写入权限,但没有显示对话框。我进入监视器没有写权限消息。 if(ContextCompat.che
由于 Android 去年添加,Android API 版本 23 及更高版本中的运行时权限问题,我有一个关于 ActivityCompat.requestPermissions(thisActivi
我的 Cordova 应用程序使用 DeviceMotionEvent.requestPermission() 函数来请求用户访问 iOS 设备方向的权限。但iOS生成的提示是: "" Would L
浏览器一直放弃请求通知权限,只是决定它是默认的。我怎样才能让它请求许可,这样我才能真正接受? 最佳答案 这个有效: Notification.requestPermission().then(func
没有调用 onRequestPermissionsResult() 的任何原因? 在 Activity A 中,我有 requestPermission(Permission A, Permissio
我有一个应用程序需要请求永久访问地理定位权限(也在后台)以收集数据。在应用程序启动时,我会像这样进行权限检查(简化) private static function check():void{
在 AndroidManifest.xml 中: 在 PreActivity.java 中 if (PermissionChecker.checkSelfPermission(preActivit
我遇到一个问题,一个函数的实现在较新的浏览器中发生了变化。我想根据实现相应地调用该函数。 Notification.requestPermission().then(function (permiss
我正在尝试请求 ACCESS_FINE_LOCATION 权限以获取用户的当前位置。 我的日志记录表明我的应用在查询 ContextCompat.checkSelfPermission() 时目前没有
调用 ActivityCompat.requestPermissions 不显示 UI 对话框。 ActivityCompat.requestPermissions(MainActivity.this
我对编程比较陌生,刚刚制作了一个相机应用程序,其预览窗口保存在表面 View 中,需要访问位置,显然还有相机。 但是,在显示一个权限的 requestPermissionRationale 并且用户同
if (ContextCompat.checkSelfPermission(RegisterActivity.this, Manifest.permission.READ_PHONE_STA
我不想让我的用户在他们真正需要应用程序之前允许通知。 因此,当用户在我的应用程序中安排本地通知时,我想请求通知权限,如果用户接受,则设置本地通知。 问题是 PushNotificationIOS.re
Notification.requestPermission() 函数已从回调更改为基于 promise 的版本。您可以在 Mozilla documentation 中看到这一点. 为当前浏览器选择
这可能是一个非常愚蠢的问题。 我有一个几年前使用 Eclipse 编写的应用程序,适用于 Android OS 8 (2.3.x)。我正在尝试将其带入现代世界(仍然使用 8 构建,但目标是 28),并
我正在尝试使用连接到我的 Android 设备的 USB 摄像头设备。所以最初我通过 UsbManager.getDeviceList() 方法获得了连接的 USB 设备的详细信息。然后我遍历每个设备
我需要在我的应用程序中访问照片和 map 。所以我在 plist 文件中添加了相应的功能。但是我需要检查请求是否被允许或拒绝。我不知道该怎么做,请建议我这个。 最佳答案 您必须明确检查不同类型的权限,
我是一名优秀的程序员,十分优秀!