iOS 开发相机,相册权限问题,代码总结

//调用相机

 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:picker animated: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:picker animated: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:zyqAssetVC animated: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];

}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值