试着这样做:
对于
:
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized)
{
[self accessCamera];
}
else if(authStatus == AVAuthorizationStatusNotDetermined)
{
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
{
if(granted)
{
[self accessCamera];
}
else
{
[self deniedCamera];
}
}];
}
else
{
[self deniedCamera];
}
对于
照片库
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusAuthorized) {
[self accessPhotoLibrary];
}
else if (status == PHAuthorizationStatusNotDetermined) {
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusAuthorized) {
[self accessPhotoLibrary];
}else {
[self deniedPhotoLibrbary];
}
}];
}
else {
[self deniedPhotoLibrbary];
}
-(void)accessCamera{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:picker animated:YES completion:NULL];
});
}
-(void)accessPhotoLibrary{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = YES;
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:picker animated:YES completion:NULL];
});
}
didFinishPickingMediaWithInfo
方法