相册权限 第一次安装、用户是否授权

来源:互联网 发布:黑帽seo免杀jsp大马 编辑:程序博客网 时间:2024/06/05 02:42

void (^allowEvent)() = ^{

        UIImagePickerControllerSourceType sourceType;

        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        UIImagePickerController *picker = [[UIImagePickerControlleralloc]init];

        picker.delegate = self;

        picker.sourceType = sourceType;

        picker.allowsEditing = YES;

        UIViewController *ctl = [[[UIApplicationsharedApplication]windows]lastObject].rootViewController;

        [ctl presentViewController:pickeranimated:YEScompletion:nil];

    };

    if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

        PHAuthorizationStatus author = [PHPhotoLibraryauthorizationStatus];

        if (author ==PHAuthorizationStatusNotDetermined) {

            [PHPhotoLibraryrequestAuthorization:^(PHAuthorizationStatus status) {

                dispatch_async(dispatch_get_main_queue(), ^{

                    if (status == PHAuthorizationStatusAuthorized) {

                        allowEvent();

                    }else{

                        showAlert(@"用户取消相册授权,请在设置中启用");

                    }

                });

            }];

            return;

        }elseif(author ==PHAuthorizationStatusRestricted || author == PHAuthorizationStatusDenied){

            showAlert(@"相册权限受限,请在设置中启用");

            return;

        }

        allowEvent();

    }

0 0