2017-08-02 4 views
0

Ich habe Erlaubnis der Kamera verweigert, aber Erlaubnis der photolibrary vorher gegeben. Aber die Kamera öffnet sich mit einem schwarzen Bildschirm. und ich kann die Option sehen, Fotos zu machen. Gibt es eine Möglichkeit, die Kamera nicht zu öffnen?Wenn Photolibrary Erlaubnis gegeben wird und Kamera Erlaubnis nicht gegeben wird, dann öffnet Kamera und nimmt ein leeres Foto

Mein Code ist wie folgt

-(void)showImagePickerWithSoureType:(UIImagePickerControllerSourceType)type 
{ 
    if([UIImagePickerController isSourceTypeAvailable:type]) 
    { 
     pickerObj = [UIImagePickerController new]; 
     pickerObj.sourceType = type; 
     UIViewController *topMostViewController = [CommonFunctions getTopMostViewControllerFromRootViewController:[CommonFunctions getAppDelegateObject].window.rootViewController]; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      [topMostViewController presentViewController:pickerObj animated:YES completion:NULL]; 
      pickerObj.delegate = self; 
      pickerObj.editing = true; 
      pickerObj.allowsEditing = true; 
     }); 


     if([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusNotDetermined) 
     { 
      [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { 
       switch (status) { 
        case PHAuthorizationStatusAuthorized: 
         break; 
        case PHAuthorizationStatusRestricted: 
         [self imagePickerControllerDidCancel:pickerObj]; 
         break; 
        case PHAuthorizationStatusDenied: 
         [self imagePickerControllerDidCancel:pickerObj]; 
         break; 
        default: 
         break; 
       } 
      }]; 
     } 
    } 
} 

Antwort

0

wie Try this:

Für Kamera:

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; 
    if(authStatus == AVAuthorizationStatusAuthorized) 
    { 
     [self accessCamera]; 
    } 
    else if(authStatus == AVAuthorizationStatusNotDetermined) 
    { 

     [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) 
     { 
      if(granted) 
      { 
       [self accessCamera]; 
      } 
      else 
      { 
       [self deniedCamera]; 
      } 
     }]; 
    } 
else 
{ 
      [self deniedCamera]; 
} 

Für Photolibrary:

PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; 

if (status == PHAuthorizationStatusAuthorized) { 
    [self accessPhotoLibrary]; 
} 
else if (status == PHAuthorizationStatusNotDetermined) { 

    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { 

     if (status == PHAuthorizationStatusAuthorized) { 
      [self accessPhotoLibrary]; 
     }else { 
      [self deniedPhotoLibrbary]; 
     } 
    }]; 
} 
else { 
    [self deniedPhotoLibrbary]; 
} 

Und die Methoden picker Teilnehmer Sie können anrufen

-(void)accessCamera{   


    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.allowsEditing = YES; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      [self presentViewController:picker animated:YES completion:NULL]; 
     }); 
} 


-(void)accessPhotoLibrary{ 
     UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
     picker.allowsEditing = YES; 
     picker.delegate = self; 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      [self presentViewController:picker animated:YES completion:NULL]; 
     }); 

} 

Dann Bild erhalten von didFinishPickingMediaWithInfo Methode.

Verwandte Themen