0

My application terminates showing Message from debugger: Terminated due to signal 9 after doing rigorous searching didn't find any thing , i have also checked for memory leaks but does not find any..

Problem Statement - When i open camera from my app and after capturing image when i select use image my app terminates.

My Code

- (void)imagePickerController:(UIImagePickerController )picker didFinishPickingMediaWithInfo:(NSDictionary )info {

   UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
   UIImageWriteToSavedPhotosAlbum(chosenImage, nil, nil, nil);
   [picker dismissViewControllerAnimated:YES completion:NULL];

}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87

1 Answers1

0

I used to select image from both camera and gallery using imagepicker with uialertactionsheet. This code is working for me, so you try this. And use these delegate's

- (IBAction)Camera_Click:(id)sender
{
        UIAlertController *alertView = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

    // Photos from Gallery by calling Method
        UIAlertAction *choose = [UIAlertAction actionWithTitle:@"Select from photos" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){

        [self performSelector:@selector(choosePhotoFromGallery)];

    [alertView dismissViewControllerAnimated:YES completion:nil ];

        }];

        //Take New Photo From Camara
        UIAlertAction *Capture = [UIAlertAction actionWithTitle:@"Capture from camera" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){

     [self performSelector:@selector(takePhotoFromCamara)];

        [alertView dismissViewControllerAnimated:YES completion:nil ];

            }];
        UIAlertAction *Cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action){



            }];

        //Adding the alertView Actions

        [alertView addAction:choose];
        [alertView addAction:Capture];
        [alertView addAction:Cancel];

     //Presents the AlertView
        [self presentViewController:alertView animated:YES completion:nil];


    }
- (void)takePhotoFromCamara 
    {

        UIImagePickerController *Take_pic = [[UIImagePickerController alloc] init];
        Take_pic.delegate = self;
            Take_pic.allowsEditing = YES;
            Take_pic.sourceType = UIImagePickerControllerSourceTypeCamera;

            [self presentViewController:Take_pic animated:YES completion:NULL];

    }


- (void)choosePhotoFromGallery 
    {

        UIImagePickerController *Choose_picker = [[UIImagePickerController alloc] init];
            Choose_picker.delegate = self;
            Choose_picker.allowsEditing = YES;
            Choose_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

            [self presentViewController:Choose_picker animated:YES completion:NULL];

    }


    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
    {

            UIImage *imgPicker = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
            self.your_imgView.image = imgPicker;

            [picker dismissViewControllerAnimated:YES completion:NULL];

    }


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
    {

        [picker dismissViewControllerAnimated:YES completion:NULL];

    }


**Finally you add this two in your app info.plist file, otherwise app will crash.
  <key>NSPhotoLibraryUsageDescription</key>
  <string><$YourAppname$>We access your photo library.</string>
  <key>NSCameraUsageDescription</key>
  <string><$YourAppname$>We access your camera.</string>**