ZZPhotoController.m
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// ZZPhotoController.m
// ZZFramework
//
// Created by Yuan on 15/12/16.
// Copyright © 2015年 zzl. All rights reserved.
//
#import "ZZPhotoController.h"
#import "ZZPhotoListViewController.h"
@interface ZZPhotoController()
@property(strong,nonatomic) ZZPhotoListViewController *photoListController;
@property(strong,nonatomic) UINavigationController *photoListNavigationController;
@end
@implementation ZZPhotoController
@synthesize photoPickerController;
#pragma mark ---- 懒加载控制器
-(ZZPhotoListViewController *)photoListController{
if (!_photoListController) {
_photoListController = [[ZZPhotoListViewController alloc]init];
}
return _photoListController;
}
-(UINavigationController *)photoListNavigationController{
if (!_photoListNavigationController) {
_photoListNavigationController = [[UINavigationController alloc]initWithRootViewController:self.photoListController];
}
return _photoListNavigationController;
}
-(ZZPhotoPickerViewController *)photoPickerController{
if (!photoPickerController) {
photoPickerController = [[ZZPhotoPickerViewController alloc]init];
}
return photoPickerController;
}
#pragma mark ---- 弹出控制器
-(void)showIn:(UIViewController *)controller result:(ZZPhotoResult)result{
//相册权限判断
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusDenied) {
//相册权限未开启
[self showAlertViewToController:controller];
}else if(status == PHAuthorizationStatusNotDetermined){
//相册进行授权
/* * * 第一次安装应用时直接进行这个判断进行授权 * * */
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
//授权后直接打开照片库
if (status == PHAuthorizationStatusAuthorized){
dispatch_async(dispatch_get_main_queue(), ^{
[self showController:controller result:result];
});
}
}];
}else if (status == PHAuthorizationStatusAuthorized){
[self showController:controller result:result];
}
}
-(void)showController:(UIViewController *)controller result:(ZZPhotoResult)result
{
//授权完成,打开相册
//Block传值
self.photoListController.photoResult = result;
//先向presentViewController控制器ZZPhotoListViewController,此控制器为全部相册控制器
/* * * 同时设定最多选择照片的张数 * * */
self.photoListController.selectNum = _selectPhotoOfMax;
[self showPhotoList:controller];
//Block传值
self.photoPickerController.PhotoResult = result;
self.photoPickerController.isAlubSeclect = NO;
self.photoPickerController.roundColor = self.roundColor;
/* * * 同时设定最多选择照片的张数 * * */
self.photoPickerController.selectNum = _selectPhotoOfMax;
//然后再执行pushViewController控制器ZZPhotoPickerViewController
//此控制器为详情相册,显示某个相册中的详细照片
[self showPhotoPicker:self.photoListController.navigationController];
}
-(void)showPhotoList:(UIViewController *)controller
{
[controller presentViewController:self.photoListNavigationController animated:YES completion:nil];
}
-(void)showPhotoPicker:(UINavigationController *)navigationController
{
//此处注意Animated == NO,关闭动画效果。则直接进入了详细页面。
[navigationController pushViewController:self.photoPickerController animated:NO];
}
-(void)showAlertViewToController:(UIViewController *)controller
{
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
// app名称
NSString *appName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提醒" message:[NSString stringWithFormat:@"请在iPhone的“设置->隐私->照片”开启%@访问你的手机相册",appName] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
}];
[alert addAction:action1];
[controller presentViewController:alert animated:YES completion:nil];
}
@end