info.plist文件配置字段
1 . 定位权限 : Privacy - Location When In Use Usage Description
2 . 通讯录权限: Privacy - Contacts Usage Description
3 . 相机权限 : Privacy - Camera Usage Description
4 . 相册权限 : Privacy - Photo Library Usage Description
5 . 麦克风权限 : Privacy - Microphone Usage Description
定位权限 : #import < CoreLocation/CoreLocation.h>
//定位权限状态
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusRestricted) {
return;
}else if (status == kCLAuthorizationStatusNotDetermined){
//请求用户授权
[self.manager requestWhenInUseAuthorization];
}else{
//定位相关设置
self.manager.delegate = self;
self.manager.desiredAccuracy = kCLLocationAccuracyBest;
self.manager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
//开始定位
[self.manager startUpdatingLocation];
}
相册权限 #import < Photos/Photos.h>
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
switch (status) {
//未决定
case PHAuthorizationStatusNotDetermined:
{
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusRestricted ||
status == PHAuthorizationStatusDenied) {
}else{
//打开相册
[self uploadOperationWithOperationStyle:JYUploadOperationStylePhoto];
}
}];
}
break;
//拒绝
case AVAuthorizationStatusRestricted:
{
//引导用户打开权限
[NSObject alertShowForAuthorizationWithTarget:nil callBack:^{
//打开用户设置
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}];
}
break;
//已经授权过
case AVAuthorizationStatusAuthorized:
{
//打开相册
[self uploadOperationWithOperationStyle:JYUploadOperationStylePhoto];
}
break;
default:
break;
}
通讯录权限 #import < AddressBook/AddressBook.h>
// kABAuthorizationStatusNotDetermined = 0, 未决定
// kABAuthorizationStatusRestricted, 特殊原因禁止访问用户通讯录
// kABAuthorizationStatusDenied, 用户拒绝访问
// kABAuthorizationStatusAuthorized 已经授权访问
// 倒数第二种除非用户在设置里主动打开。否则在APP里永远无法访问 。 只有第一种情况下,才会告知用户授权。
//判断用户授权状态
ABAuthorizationStatus state = ABAddressBookGetAuthorizationStatus();
//判断 如果授权状态是未决定的,则请求授权
if (state == kABAuthorizationStatusNotDetermined) {
//请求
//1.获取通讯录对象
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
//2.请求授权 (用户决定后就会回调block)
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (granted) {
NSLog(@"用户授权成功");
}else{
NSLog(@"用户授权失败");
}
});
}
相机权限
//权限判断
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
switch (authStatus) {
//未决定状态
case AVAuthorizationStatusNotDetermined:
{
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
//接收
if (granted) {
[self takePhotos];
}
}];
}
break;
//拒绝
case AVAuthorizationStatusRestricted:
{
//alert提示用户去设置里打开权限
}
break;
case AVAuthorizationStatusAuthorized:
{
[self takePhotos];
}
break;
default:
break;
}
//拍照或录像
- (void)takePhotos
{
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;// 设置类型
NSString *requiredMediaType = ( NSString *)kUTTypeImage;
NSString *requiredMediaType1 = ( NSString *)kUTTypeMovie;
NSArray *arrMediaTypes=[NSArray arrayWithObjects:requiredMediaType, requiredMediaType1,nil];
controller.mediaTypes = arrMediaTypes;
// 设置录制视频的质量
controller.videoQuality = UIImagePickerControllerQualityTypeHigh;
//设置最长摄像时间
controller.videoMaximumDuration = 10.f;
//设置代理 回调方法 , 之前文章有写过 , 这里就不写了
controller.delegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
//然后在代理方法中得到内容 ...
代理回调方法
http://blog.csdn.net/codermy/article/details/53055861
麦克风权限
AVAudioSessionRecordPermission status = [[AVAudioSession sharedInstance]recordPermission];
switch (status) {
//未决定状态
case AVAudioSessionRecordPermissionUndetermined:
{
[[AVAudioSession sharedInstance]requestRecordPermission:^(BOOL granted) {
if (granted) {
//打开麦克风录音
}
}];
}
break;
//已经取得权限
case AVAudioSessionRecordPermissionGranted:
//打开麦克风录音
break;
default:
break;
}