UIImagePickerController在iOS11访问相册

iOS11来了以后,最近审核被拒绝,原因是:弹出系统权限的时候,必须说出用途。否则会被以
Guideline 5.1.2 - Legal - Privacy - Data Use and Sharing
拒绝你。很难理解苹果的思想,谁让人家整出了苹果神机,垄断了市场。。。还是不说了,直接说这个问题。

我查了资料很难找到直接1.2句代码能解决这个问题的方法,最后还是自己写的提示,只是获取了权限,和系统的弹框一样的效果。直接上代码。

//相册权限

    NSInteger status = [self.classauthorizationStatus];

if (status == 0) {

        /**

         * 当某些情况下AuthorizationStatus == AuthorizationStatusNotDetermined时,无法弹出系统首次使用的授权alertView,系统应用设置里亦没有相册的设置,此时将无法使用,故作以下操作,弹出系统首次使用的授权alertView

         */

        [selfrequestAuthorizationWithCompletion:nil];

}

- (void)requestAuthorizationWithCompletion:(void (^)())completion {

    void (^callCompletionBlock)() = ^(){

        dispatch_async(dispatch_get_main_queue(), ^{

            if (completion) {

                completion();

            }

        });

    };

    

    if (iOS8Later) {

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{

            [PHPhotoLibraryrequestAuthorization:^(PHAuthorizationStatus status) {

                callCompletionBlock();

            }];

        });

    } else {

        [self.assetLibraryenumerateGroupsWithTypes:ALAssetsGroupAllusingBlock:^(ALAssetsGroup *group,BOOL *stop) {

            callCompletionBlock();

        } failureBlock:^(NSError *error) {

            callCompletionBlock();

        }];

    }

}


当  status = 3;是用户点击了允许,是默认可以的。

其他值的时候如下:

当不是允许的时候这个时候,我们就可以做到与系统一样的效果了,甚至比它的效果还要好,上面的代码即可提示了,

我们还可以加一些其他的操作,当选择允许的时候,那就开始你之前的代码直接进入相册,不是选择允许的话,我们就可以写个界面加个跳转,效果可能会更好

 NSString *appName = [infoDict valueForKey:@"CFBundleDisplayName"];

            if (!appName) appName = [infoDict valueForKey:@"CFBundleName"];

            NSString *tipText = [NSStringstringWithFormat:[NSBundletz_localizedStringForKey:@"Allow %@ to access your album in \"Settings -> Privacy -> Photos\""],appName];

            _tipLabel.text = tipText;

            [PhotobgViewaddSubview:_tipLabel];

            

            NSString *settingBtnTitleStr = [NSBundletz_localizedStringForKey:@"Setting"];

            if (iOS8Later) {

                _settingBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];

                [_settingBtn setTitle:settingBtnTitleStr forState:UIControlStateNormal];

                _settingBtn.frame =CGRectMake(0,180, self.view.tz_width,44);

                _settingBtn.titleLabel.font = [UIFontsystemFontOfSize:18];

                [_settingBtnaddTarget:selfaction:@selector(settingBtnClick)forControlEvents:UIControlEventTouchUpInside];

                [PhotobgViewaddSubview:_settingBtn];

            }

            

            _timer = [NSTimerscheduledTimerWithTimeInterval:0.2target:selfselector:@selector(observeAuthrizationStatusChange)userInfo:nilrepeats:YES];



这个是跳转到相册权限 

[[UIApplication sharedApplication]openURL:[NSURLURLWithString:UIApplicationOpenSettingsURLString]];


而我加一个时钟是为了时时刻刻监听相册权限,一旦打开,立刻把自己写的东西移除了。

 if ([[TZImageManagermanager] authorizationStatusAuthorized]) {}

这里面操作,直接进入相册了。


大致思路就是这个,我把效果图截图一下: