相册权限 第一次安装、用户是否授权
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();
}
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();
}
相关文章推荐
- Python面向对象学习(2)
- esVSsolr
- [LeetCode] Alien Dictionary 另类字典
- 赵雅智:js知识点汇总
- 判断单链表是否有环
- 51单片机系列知识16--HD7279(2)
- Mybatis入门(二):以接口的方式编程
- 卡方检验
- 我所理解的网站架构
- Tomcat 默认支持的处理请求的并发数量
- SVN服务器的本地搭建和使用
- oracle exp imp 高低版本问题
- 4. PSR-4 --- 自动加载
- OutputStreamWriter, PrintWriter, BufferedWriter, FileWrite, PrintStream
- 【Python】python代码如何调试?
- iOS开发之使用lipo命令制作模拟器与真机通用静态库
- Python wsgiref 模块源码浅析
- 【转】小结登录的几种交互方式
- Eclipse如何安装JD-Eclipse反编译插件
- SSH框架功能介绍