您的位置:首页 > 其它

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

2016-03-07 13:35 253 查看
void (^allowEvent)() = ^{

        UIImagePickerControllerSourceType sourceType;

        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        UIImagePickerController *picker = [[UIImagePickerController
alloc]init];

        picker.delegate =
self;

        picker.sourceType = sourceType;

        picker.allowsEditing =
YES;

        UIViewController *ctl = [[[UIApplication
sharedApplication]
windows]lastObject].rootViewController;

        [ctl presentViewController:picker
animated:YES
completion:nil];

    };

    if ([UIImagePickerController
isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

        PHAuthorizationStatus author = [PHPhotoLibrary
authorizationStatus];

        if (author ==
PHAuthorizationStatusNotDetermined) {

            [PHPhotoLibrary
requestAuthorization:^(PHAuthorizationStatus status) {

                dispatch_async(dispatch_get_main_queue(), ^{

                    if (status ==
PHAuthorizationStatusAuthorized) {

                        allowEvent();

                    }else{

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

                    }

                });

            }];

            return;

        }else
if(author ==
PHAuthorizationStatusRestricted || author ==
PHAuthorizationStatusDenied){

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

            return;

        }

        allowEvent();

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: