|
10 | 10 |
|
11 | 11 | #import "DWOrigImageView.h" |
12 | 12 | #import "UIView+Extend.h" |
| 13 | +#import <Photos/Photos.h> |
13 | 14 | //#import "DWContentScrollView.h" |
14 | 15 |
|
15 | 16 |
|
@@ -93,7 +94,30 @@ - (void)addContentView{ |
93 | 94 |
|
94 | 95 |
|
95 | 96 | - (void)saveImage{ |
96 | | - UIImageWriteToSavedPhotosAlbum(self.imgView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); |
| 97 | + // 判断授权状态 |
| 98 | + PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; |
| 99 | + if (status == PHAuthorizationStatusNotDetermined) { // 用户还没有做出选择 |
| 100 | + // 弹框请求用户授权 |
| 101 | + [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { |
| 102 | + if (status == PHAuthorizationStatusAuthorized) { // 用户第一次同意了访问相册权限 |
| 103 | + UIImageWriteToSavedPhotosAlbum(self.imgView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); |
| 104 | + } |
| 105 | + }]; |
| 106 | + } else if (status == PHAuthorizationStatusAuthorized) { // 用户允许当前应用访问相册 |
| 107 | + NSLog(@"用户允许当前应用访问相册"); |
| 108 | + UIImageWriteToSavedPhotosAlbum(self.imgView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); |
| 109 | + } else if (status == PHAuthorizationStatusDenied) { // 用户拒绝当前应用访问相册 |
| 110 | + dispatch_async(dispatch_get_main_queue(), ^{ |
| 111 | + UIAlertView * alart = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"请您设置允许APP访问您的照片\n设置>隐私>照片" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; |
| 112 | + [alart show]; |
| 113 | + }); |
| 114 | + |
| 115 | + } else if (status == PHAuthorizationStatusRestricted) { |
| 116 | + dispatch_async(dispatch_get_main_queue(), ^{ |
| 117 | + UIAlertView * alart = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"由于系统限制, 无法访问相册" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; |
| 118 | + [alart show]; |
| 119 | + }); |
| 120 | + } |
97 | 121 | } |
98 | 122 |
|
99 | 123 |
|
@@ -163,8 +187,6 @@ - (void)clickPinchView:(UIPinchGestureRecognizer *)gest{ |
163 | 187 | } |
164 | 188 | } |
165 | 189 | }]; |
166 | | - |
167 | | - |
168 | 190 | }else{ |
169 | 191 | if (_contentScrollView.contentSize.width != view.width) { |
170 | 192 | if (view.height>screenH) { |
|
0 commit comments