iOS 开发相机,相册权限问题,代码总结
来源:互联网 发布:发那科机器人编程实例 编辑:程序博客网 时间:2024/06/01 08:00
//调用相机
UIActionSheet *actionSheet = [[UIActionSheetalloc]initWithTitle:nildelegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"拍照",@"相册",nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
/**actionSheet 代理方法*/
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
{
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusDenied){
UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:nilmessage:@"请在iPhone的设置-隐私-相机选项中,允许美不美访问你的相机"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil];
[alertView show];
}else{
UIImagePickerController *picker = [[UIImagePickerControlleralloc]init];
picker.delegate = self;//
picker.allowsEditing = YES;
picker.sourceType =UIImagePickerControllerSourceTypeCamera;//UIImagePicker选择器的类型,UIImagePickerControllerSourceTypeCamera调用系统相机
[selfpresentViewController:pickeranimated:YEScompletion:NULL];
}
}else{
//如果当前设备没有摄像头
UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:nilmessage:@"当前设备没有摄像头。"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil];
[alertView show];
}
break;
}
case 1:
{
PhotoPickerViewController *picker = [[PhotoPickerViewControlleralloc]init];
picker.maximumNumberOfSelection =9;
picker.assetsFilter = [ALAssetsFilterallPhotos];
picker.showEmptyGroups=NO;
picker.delegate=self;
picker.selectionFilter = [NSPredicatepredicateWithBlock:^BOOL(id evaluatedObject,NSDictionary *bindings) {
if ([[(ALAsset*)evaluatedObjectvalueForProperty:ALAssetPropertyType]isEqual:ALAssetTypeVideo]) {
NSTimeInterval duration = [[(ALAsset*)evaluatedObjectvalueForProperty:ALAssetPropertyDuration]doubleValue];
return duration >= 5;
} else {
return YES;
}
}];
[self.selectedViewControllerpresentViewController:pickeranimated:YEScompletion:NULL];
break;
}
case 2:
{
break;
}
default:
break;
}
}
#pragma mark - ZYQAssetPickerController Delegate
-(void)assetPickerController:(ZYQAssetPickerController *)picker didFinishPickingAssets:(NSArray *)assets{
//点击的照片 assets
// UIStoryboard *CameraStoryBoard = [UIStoryboard storyboardWithName:@"Camera" bundle:nil];
// CameraView = [CameraStoryBoard instantiateViewControllerWithIdentifier:@"CameraView"];
UIStoryboard *TailorStoryBoard = [UIStoryboardstoryboardWithName:@"TailorImageController"bundle:nil];
TailorController = [TailorStoryBoardinstantiateViewControllerWithIdentifier:@"TailorImageController"];
//图片降质
NSMutableArray *tempImageArray = [NSMutableArrayarray];
for (ALAsset *assetin assets) {
UIImage *OldImg=[UIImageimageWithCGImage:asset.defaultRepresentation.fullResolutionImage];
NSData *tempImageData = UIImageJPEGRepresentation(OldImg, 0.4);
UIImage *NewImage = [UIImageimageWithData:tempImageData];
[tempImageArray addObject:NewImage];
}
// CameraView.photoArray = tempImageArray;
TailorController.photoArray = tempImageArray;
// [UIApplication sharedApplication].keyWindow.rootViewController = CameraViewNvc;
[selfperformSelector:@selector(IssueViewController)withObject:nilafterDelay:0.2];
// [self.selectedViewController.navigationController pushViewController:CameraView animated:NO];
}
//发布界面
- (void)IssueViewController
{
// [self.selectedViewController pushViewController:CameraView animated:NO];
[self.selectedViewControllerpushViewController:TailorControlleranimated:NO];
}
//相册取消
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
if ( picker.sourceType ==UIImagePickerControllerSourceTypeCamera) {
[picker dismissViewControllerAnimated:NOcompletion:nil];
}else{
ZYQAssetPickerController * zyqAssetVC = [[ZYQAssetPickerControlleralloc]init];
[self.navigationControllerpresentViewController:zyqAssetVCanimated:YEScompletion:nil];
}
}
//相机拍照功能选区照片
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:NOcompletion:^{
}];
// UIStoryboard *CameraStoryBoard = [UIStoryboard storyboardWithName:@"Camera" bundle:nil];
// CameraView = [CameraStoryBoard instantiateViewControllerWithIdentifier:@"CameraView"];
UIStoryboard *TailorStoryBoard = [UIStoryboardstoryboardWithName:@"TailorImageController"bundle:nil];
TailorController = [TailorStoryBoardinstantiateViewControllerWithIdentifier:@"TailorImageController"];
//图片降质
UIImage *OldImg =info[UIImagePickerControllerOriginalImage];
NSData *tempImageData = UIImageJPEGRepresentation(OldImg, 0.75);
UIImage *NewImage = [UIImageimageWithData:tempImageData];
// CameraView.photoArray = [NSArray arrayWithObjects:NewImage, nil];
TailorController.photoArray = [NSArrayarrayWithObjects:NewImage,nil];
[selfperformSelector:@selector(IssueViewController)withObject:nilafterDelay:0.2];
}
- iOS 开发相机,相册权限问题,代码总结
- iOS 相册相机权限
- iOS相机相册使用权限
- iOS相册权限、相机权限、麦克风权限
- iOS相册权限、相机权限、麦克风权限
- iOS 解决iOS10相册、相机、麦克风等权限使用问题
- iOS 10 设备权限问题(相机,相册等)
- iOS中 iOS10 调用相机相册等权限崩溃问题
- iOS中 iOS10 相机相册等权限崩溃问题
- iOS开发中使用相机或系统相册的一些问题总结(UIImagePickerController)
- iOS 相机权限以及相册权限访问
- iOS开发 - 访问相机相册
- iOS开发 iOS10访问权限的配置(解决访问奔溃问题,包括相册/相机等)
- IOS开发之相机、相册页面英文问题
- ios 判断相册 相机 位置权限
- ios 判断相册 相机 位置权限
- iOS相机,相册等访问权限
- iOS相册、相机、通讯录权限获取
- rabbitmq 启动
- Nimble packages
- iOS隐藏状态栏
- angularJS学习之路(二十)---自定义指令---transclude的作用
- UESTC 1059 线段树离散化
- iOS 开发相机,相册权限问题,代码总结
- Bootstrap的Datatable详解
- UVa 11231 - Black and white painting
- 黑马程序员——网络编程一
- java 调用C的API
- generator函数
- aaa
- 如何调用外部的项目的Activity
- safari网页翻译