- <!– 相册 –> <key>NSPhotoLibraryUsageDescription</key> <string>App需要您的同意,才能访问相册</string>
- <!– 相机 –> <key>NSCameraUsageDescription</key> <string>App需要您的同意,才能访问相机</string>
- <!– 麦克风 –> <key>NSMicrophoneUsageDescription</key> <string>App需要您的同意,才能访问麦克风</string>
- <!– 位置 –> <key>NSLocationUsageDescription</key> <string>App需要您的同意,才能访问位置</string>
- <!– 在使用期间访问位置 –> <key>NSLocationWhenInUseUsageDescription</key> <string>App需要您的同意,才能在使用期间访问位置</string>
- <!– 始终访问位置 –> <key>NSLocationAlwaysUsageDescription</key> <string>App需要您的同意,才能始终访问位置</string>
- <!– 日历 –> <key>NSCalendarsUsageDescription</key> <string>App需要您的同意,才能访问日历</string>
- <!– 提醒事项 –> <key>NSRemindersUsageDescription</key> <string>App需要您的同意,才能访问提醒事项</string>
- <!– 运动与健身 –> <key>NSMotionUsageDescription</key> <string>App需要您的同意,才能访问运动与健身</string>
- <!– 健康更新 –> <key>NSHealthUpdateUsageDescription</key> <string>App需要您的同意,才能访问健康更新 </string>
- <!– 健康分享 –> <key>NSHealthShareUsageDescription</key> <string>App需要您的同意,才能访问健康分享</string>
- <!– 蓝牙 –> <key>NSBluetoothPeripheralUsageDescription</key> <string>App需要您的同意,才能访问蓝牙</string>
- <!– 媒体资料库 –> <key>NSAppleMusicUsageDescription</key> <string>App需要您的同意,才能访问媒体资料库</string>
info.plist中逐个添加 KEY直接复制 value的string字符串就是提示的文字 可以根据自己需要填写
==============
#import<AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
#import<AssetsLibrary/AssetsLibrary.h>
#import<CoreLocation/CoreLocation.h>
//相机权限—-
//下面这个方法tatus为AVAuthorizationStatusNotDetermined时,下面的方法就无效了,要用+requestAccessForMediaType:completionHandler:
AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeVideo];
if (authStatus ==AVAuthorizationStatusRestricted ||//此应用程序没有被授权访问的照片数据。可能是家长控制权限
authStatus ==AVAuthorizationStatusDenied) //用户已经明确否认了这一照片数据的应用程序访问
{
// 无权限 引导去开启
NSURL *url = [NSURLURLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplicationsharedApplication]canOpenURL:url]) {
[[UIApplicationsharedApplication]openURL:url];
}
}
//相册权限
ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus];
if (author ==kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){
//无权限 引导去开启
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}
/** 设置相册权限 */ – (void)openAlbumReject { NSURL *url = [NSURL URLWithString:@”prefs:root=com.xxxx.xxxx”]; // 这里填你App的Bundle ID if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url]; } }
参考:http://www.jianshu.com/p/3bbc69132ba0
iOS9以后
#import <Photos/Photos.h>
//获取相册访问权限
// PHAuthorizationStatus photoStatus = [PHPhotoLibrary authorizationStatus];
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
dispatch_async(dispatch_get_main_queue(), ^{
switch (status) {
case PHAuthorizationStatusAuthorized: //已获取权限
{ //加上这个在主线程异步就不卡顿了
dispatch_async(dispatch_get_main_queue(), ^{
[self dealDownloadImageStr];
});
break;
}
case PHAuthorizationStatusDenied: {
//用户已经明确否认了这一照片数据的应用程序访问
UIAlertController *controller=[UIAlertController alertControllerWithTitle:@”去设置页面-》2号钱包-》选择读取和写入” message:@”” preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sure=[UIAlertAction actionWithTitle:@”去开启权限” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
dispatch_async(dispatch_get_main_queue(), ^{
if( [[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
}
});
}];
UIAlertAction *cancel=[UIAlertAction actionWithTitle:@”暂不” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[controller addAction:sure];
[controller addAction:cancel];
[self presentViewController:controller animated:YES completion:^{
}];
break;
}
case PHAuthorizationStatusRestricted://此应用程序没有被授权访问的照片数据。
break;
default://其他。。。
break;
}
});
}];
相机权限:
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
//相机
sourceType = UIImagePickerControllerSourceTypeCamera;
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
AVAuthorizationStatus status =[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusAuthorized){
//获取权限
// 跳转到相机或相册页面
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
imagePickerController.sourceType = sourceType;
//弹出相册页面或相机
[self presentViewController:imagePickerController animated:YES completion:^{
}];
}else if(status == AVAuthorizationStatusDenied ||status ==AVAuthorizationStatusRestricted){
//拒绝了权限
[self gotoSetAuthor];
}
}];
-(void)gotoSetAuthor{
UIAlertController *controller=[UIAlertController alertControllerWithTitle:@”去设置页面-》2号钱包-》照片” message:@”” preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *sure=[UIAlertAction actionWithTitle:@”去开启权限” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
dispatch_async(dispatch_get_main_queue(), ^{
if( [[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
}
});
}];
UIAlertAction *cancel=[UIAlertAction actionWithTitle:@”暂不” style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[controller addAction:sure];
[controller addAction:cancel];
[self presentViewController:controller animated:YES completion:^{
}];
}
***************各种权限的申请:https://www.jianshu.com/p/27e57922232b
直接拷贝到info。plist中 以sourceas打开
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSAppleMusicUsageDescription</key>
<string>App需要您的同意,才能访问媒体资料库</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>我们需要您开启蓝牙,方便连接数据?</string>
<key>NSCalendarsUsageDescription</key>
<string>是否允许此App使用日历?</string>
<key>NSCameraUsageDescription</key>
<string>我们需要获取本机拍摄的照片,以供您选择上传</string>
<key>NSContactsUsageDescription</key>
<string>需要使用您的同意,才能使用通讯录</string>
<key>NSHealthShareUsageDescription</key>
<string>App需要您的同意,才能访问健康分享</string>
<key>NSHealthUpdateUsageDescription</key>
<string>App需要您的同意,才能访问健康更新 </string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>我们需要获取您的位置在某段时间上传,以便客户查看您的位置,估算工程进度</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>我们需要获取您的位置在某段时间上传,以便客户查看您的位置,估算工程进度</string>
<key>NSLocationUsageDescription</key>
<string>App需要您的同意,才能访问位置</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>我们需要获取您的位置上传,以便客户查看您的位置,估算工程进度</string>
<key>NSMicrophoneUsageDescription</key>
<string>我们需要启用您的麦克风,以便采集您的语音</string>
<key>NSMotionUsageDescription</key>
<string>是否允许此App使用您的传感器?</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>App需要您的同意,才能保存图片到相册</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>我们需要获取用户相册内的图片,以供您选择上传</string>
<key>NSRemindersUsageDescription</key>
<string>App需要您的同意,才能访问提醒事项</string>
<key>NSSiriUsageDescription</key>
<string>是否允许此App使用Siri?</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>是否允许此App使用语音识别?</string>
=============获取相机权限=================
#import "UIViewController+CameraGetAuthory.h"
#import <AVFoundation/AVFoundation.h>
@implementation UIViewController (CameraGetAuthory)
-(void)CameraGetAuthory{
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];//获取摄像头
if (device) {
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];//判断用户是否有权限访问相机
if (status == AVAuthorizationStatusNotDetermined) {
//请求权限
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
});
// 用户第一次同意了访问相机权限
} else {
// 用户第一次拒绝了访问相机权限
}
}];
} else if (status == AVAuthorizationStatusAuthorized) { // 用户允许当前应用访问相机
} else if (status == AVAuthorizationStatusDenied) { // 用户拒绝当前应用访问相机
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"⚠️ 警告" message:@"请去-> [设置 - 隐私 - 相机 - SGQRCodeExample] 打开访问开关" preferredStyle:(UIAlertControllerStyleAlert)];
UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
}];
[alertC addAction:alertA];
// [self presentViewController:alertC animated:YES completion:nil];
} else if (status == AVAuthorizationStatusRestricted) {
NSLog(@"因为系统原因, 无法访问相册");
}
} else {
UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"未检测到您的摄像头" preferredStyle:(UIAlertControllerStyleAlert)];
UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
}];
[alertC addAction:alertA];
// [self presentViewController:alertC animated:YES completion:nil];
}
}
@end
今天的文章ios中的权限开启问题,打开相机没反应_ios相机权限不见了[通俗易懂]分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/88936.html