前段時(shí)間更新iOS11之后,相冊(cè)部分缨恒,訪問(wèn)相冊(cè)默認(rèn)是放開(kāi)權(quán)限的谴咸,但是在保存相冊(cè)的時(shí)候,判斷權(quán)限不再能夠滿足項(xiàng)目需求骗露。在一個(gè)偶然機(jī)會(huì)翻閱文檔岭佳,找到了解決方案,期望對(duì)大家有所幫助萧锉,上代碼:
iOS11以前
#pragma mark - 訪問(wèn)相冊(cè)
+ (BOOL)CanPhotoLibary{
? ? PHAuthorizationStatus authStatus = [PHPhotoLibrary authorizationStatus];
? ? if (authStatus == PHAuthorizationStatusRestricted|| authStatus == PHAuthorizationStatusDenied) {
? ? ? ? returnNO;
? ? }else{
? ? ? ? returnYES;
? ? }
}
iOS11以后:
? [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
? ? ? ? ? ? ? ? if (status == PHAuthorizationStatusNotDetermined || status == PHAuthorizationStatusAuthorized) {
UIImageWriteToSavedPhotosAlbum(_HeadImg,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL);//保存圖片到相冊(cè)
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? //[JLHelperManagerUIAlertWithStr:@"請(qǐng)?jiān)谙到y(tǒng)設(shè)置中開(kāi)啟相冊(cè)授權(quán)"WithTitle:@"相冊(cè)授權(quán)未開(kāi)啟"WithVC:selfblock:nil];//未授權(quán)可以提示用不進(jìn)入設(shè)置里面打開(kāi)權(quán)限
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }];
感謝另外一為同行的文檔啟發(fā)特附iOS權(quán)限獲取設(shè)置