2016-06-28 11 views
0

當用戶選擇或捕獲任何圖像時,我正在檢查我的應用程序上的相機和照片權限。 我正在使用此代碼。當用戶不允許在iOS中訪問時如何關閉imagePicker

-(void)choosePhotoFromExistingImages 
{ 
    ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus]; 
    if (status == ALAuthorizationStatusDenied || status == ALAuthorizationStatusRestricted) { 
     [APPDELEGATE showAlertViewForPhotos]; 
     //show alert for asking the user to give permission  
    } 
    else{ 
     if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) 
     { 
      UIImagePickerController *controller = [[UIImagePickerController alloc] init]; 
      controller.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
      controller.allowsEditing = YES; 
      controller.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil] ; 
      controller.delegate = self; 
      [self presentViewController: controller animated: YES completion: nil]; 
     } 
    } 
} 

的代碼工作正常,但是當用戶第一次選擇不允許的照片庫它顯示黑屏就像照相機發生同樣的事情。 我需要的是,當用戶按下不允許我可以檢查該用戶已取消權限,所以我可以解僱imagepicker或相機。 enter image description here

回答

2

您可以使用ALAssetsLibrary authorizationStatus檢查它

How do I react to a user choosing "Don't Allow" when asking for permission to access Photos?

+0

是用於檢查授權我使用的唯一但是如果用戶選擇不允許第一次那麼我的圖片選擇器或相機還是存在的,我只想第一次解僱 – guru

+1

「唯一的選擇是查看authorizationStatus是否返回ALAuthorizationStatusNotDetermined。如果是,請使用ALAssetsLibrary enumerateGroupsWithTypes:usingBlock:failureBlock:並等待結果。如果得到失敗塊,再次檢查authorizationStatus如果現在是ALAuthorizationStatusDenied,那麼你知道用戶點擊「不要Al低」。」 – Proton

+0

好的謝謝老兄,同樣的事情將適用於相機? – guru

相關問題