Skip to content

Commit c982db6

Browse files
guangyaoguangyao
authored andcommitted
fix iOS11权限问题
1 parent a6cc313 commit c982db6

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

ios/RCTAuroraIMUI/DWCustomView/DWOrigImageView.m

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#import "DWOrigImageView.h"
1212
#import "UIView+Extend.h"
13+
#import <Photos/Photos.h>
1314
//#import "DWContentScrollView.h"
1415

1516

@@ -93,7 +94,30 @@ - (void)addContentView{
9394

9495

9596
- (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+
}
97121
}
98122

99123

@@ -163,8 +187,6 @@ - (void)clickPinchView:(UIPinchGestureRecognizer *)gest{
163187
}
164188
}
165189
}];
166-
167-
168190
}else{
169191
if (_contentScrollView.contentSize.width != view.width) {
170192
if (view.height>screenH) {

0 commit comments

Comments
 (0)