iOS 9에서 UIImagePickerController가 이미지를 선택하지 않음 (UIImagePickerController not picking image in iOS 9)


문제 설명

iOS 9에서 UIImagePickerController가 이미지를 선택하지 않음 (UIImagePickerController not picking image in iOS 9)

아래 코드를 사용하여 카메라 또는 사진 라이브러리에서 이미지를 선택하고 있습니다. iOS 8에서는 이미지를 멋지게 선택하고 있습니다. 그러나 iOS 9에서는 . 선택기 보기가 표시되지만 이미지를 선택하지 않습니다. 컨트롤러로 돌아가지도 않습니다. 그림을 탭하면 아무 작업도 수행되지 않습니다. 내가 뭘 잘못하고 있죠.

‑ (void)showImgaePickerViewForSourceType:(UIImagePickerControllerSourceType)sourceType
{
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
    imagePickerController.sourceType = sourceType;
    imagePickerController.allowsEditing = YES;
    imagePickerController.delegate = self;
    self.imgPickerController = imagePickerController;

    if (IS_IPAD) {
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:self.imgPickerController];
            [popover presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2‑200, self.view.frame.size.height/2 ‑ 300, 400, 400) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
            self.popOver = popover;
        }];
    }else{
             [self presentViewController:self.imgPickerController animated:YES completion:NULL];
    }
}

참조 솔루션

방법 1:

UIPopoverController is deprecated in iOS 9. Instead you should be using UIViewController with a modalPresentationStyle set to UIModalPresentationPopover.

For example:

UIImagePickerController *imagePickerController = ...;
CGRect sourceRect = CGRectMake(self.view.frame.size.width/2‑200, self.view.frame.size.height/2 ‑ 300, 400, 400);

imagePickerController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:imagePickerController animated:YES completion:nil]; 
imagePickerController.popoverPresentationController.sourceRect = sourceRect;
imagePickerController.popoverPresentationController.sourceView = self.view;

Note: UIModalPresentationPopover was introduced in iOS 8.0, if you need to support prior to 8.0 then you will need some conditional checks to use your old code in iOS 7 and the above in iOS 8+.

Note 2: I believe the technique above is also smart enough to work out if it should modally present the picker instead of a popover on iPhones (via size classes) so I don't think you need to do your IS_IPAD check.

방법 2:

I found that my app was running good on other iPhones(whether iOS 8 or iOS 9). I was not able to pick image from any other app. Then i decided to reset my iPhone. Now everything is perfect. It was'nt the code issue. It was my iPhone issue.

방법 3:

Use this code it is working fine in ios 9.I am using action sheet to show 2 options to choose.

   ‑(IBAction)imagepickertapped:(id)sender
   {
       UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Take Photo" otherButtonTitles:@"Photo Library",nil];

       popup.tag =909;
       popup.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
      [popup showInView:self.view];

   }
   ‑(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {


    if (actionSheet.tag ==909)
{

    if (buttonIndex == 0)
    {

        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            UIImagePickerController* picker = [[UIImagePickerController alloc] init];
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            // picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,kUTTypeImage,nil];

            picker.delegate = self;
            [self presentViewController:picker animated:YES completion:NULL];
        }
        else
        {


            UIAlertView *altnot=[[UIAlertView alloc]initWithTitle:@"Camera Not Available" message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [altnot show];

        }

    } else if (buttonIndex == 1) {

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        //picker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie,kUTTypeImage,nil];

        picker.delegate = self;
        picker.editing = YES;
        picker.allowsEditing = YES;

        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:picker animated:YES completion:NULL];
    }

}


 }

   ‑ (void)imagePickerController:(UIImagePickerController *)picker
    didFinishPickingImage:(UIImage *)image
              editingInfo:(NSDictionary *)editingInfo{


   [picker dismissViewControllerAnimated:YES completion:NULL];


imagedata = UIImageJPEGRepresentation(image, 0.3);


Userimage.image = image;


 }

For IPAD please refers this link

find here

방법 4:

Follow the below coding

‑ (void)imagePicker
{

   UIImagePickerController *picker = [[UIImagePickerController alloc] init];
   picker.delegate = self;
   picker.allowsEditing = YES;
   picker.sourceType = UIImagePickerControllerSourceTypeCamera;
   [self presentViewController:pickerTakePhoto animated:YES completion:nil];
}

‑ (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   UIImage *imagePicked = info[UIImagePickerControllerEditedImage];
   picker.delegate = self;
   [picker dismissViewControllerAnimated:YES completion:nil];
}
‑ (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{
   [picker dismissViewControllerAnimated:YES completion:NULL];
}

방법 5:

Since action sheets are deprecated and UIAlertController needs to be used, I am writing a similar answer for the benefit of newbies:

    ‑ (IBAction)attachImageTapped:(id)sender
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Attach image" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction* pickFromGallery = [UIAlertAction actionWithTitle:@"Take a photo"
                                                              style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
                                                              {
                                                              UIImagePickerController* picker = [[UIImagePickerController alloc] init];
                                                              picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                                                              picker.delegate = self;
                                                              [self presentViewController:picker animated:YES completion:NULL];
                                                              }

                                                          }];
    UIAlertAction* takeAPicture = [UIAlertAction actionWithTitle:@"Choose from gallery"
                                                              style:UIAlertActionStyleDefault
                                                            handler:^(UIAlertAction * action) {
                                                                UIImagePickerController* picker = [[UIImagePickerController alloc] init];
                                                                picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                                                                picker.delegate = self;
                                                                [self presentViewController:picker animated:YES completion:NULL];
                                                            }];
    UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel"
                                                           style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * action) {
                                                         }];

    [alertController addAction:pickFromGallery];
    [alertController addAction:takeAPicture];
    [alertController addAction:cancel];
    [self presentViewController:alertController animated:YES completion:nil];
}

‑(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    UIImage *imagePicked = info[UIImagePickerControllerOriginalImage];
    [picker dismissViewControllerAnimated:YES completion:nil];
}

‑(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

(by user2096064liamnicholsuser2096064Anil solankiuser3182143Koushik Ravikumar)

참조 문서

  1. UIImagePickerController not picking image in iOS 9 (CC BY‑SA 2.5/3.0/4.0)

#uiimagepickercontroller #objective-c #iOS






관련 질문

UIImagePickerController 닫기 (Dismiss UIImagePickerController)

UIImagePickerController에서 이미지 크기 조정이 작동하지 않음 (Resizing an image from UIImagePickerController not working)

사진 촬영 후 사진 사용 또는 재촬영을 선택할 수 없습니다. (After Taking Picture cannot select Use Photo or Retake)

런타임 오류를 제공하는 UIImagePicker (UIImagePicker giving runtime error)

Swift:UIImagePickerController에서 버튼의 텍스트를 변경하는 방법은 무엇입니까? (Swift: how to change the text of buttons in UIImagePickerController?)

iOS 9에서 UIImagePickerController가 이미지를 선택하지 않음 (UIImagePickerController not picking image in iOS 9)

UIImagePNGRepresentation() 내 UIImage 회전 (UIImagePNGRepresentation() rotate my UIImage)

UIImagePickerController에서 편집 사각형을 구성할 수 있습니까? (Can we config edit rectangle in UIImagePickerController)

imagePickerController를 닫는 방법? (how to close imagePickerController?)

카메라 사용 설명/사진 라이브러리 사용 설명을 추가해도 경고가 표시되지 않음 (Not showing alert even when I add Camera Usage Description / Photo Library Usage Description)

UIImagePIcker를 통해 "JPG", "PNG" 및 "JPEG" 이미지만 선택할 수 있는 방법이 있습니까? (Is there any way by which I can select only "JPG", "PNG" and "JPEG" images through UIImagePIcker)

사진 라이브러리 Swift에 비디오 저장 (Save video in Photo Library Swift)







코멘트