单击相机使用图像按钮目标c时终止应用程序

问题描述 投票:0回答:1

我的应用程序终止显示来自调试器的消息:在执行严格搜索后由于信号9终止没有找到任何东西,我也检查了内存泄漏但没有找到任何...

问题陈述 - 当我从我的应用程序打开相机并在我选择使用图像捕获图像后,我的应用程序终止。

我的守则

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

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

}
ios objective-c ios-camera
1个回答
0
投票

我曾经使用带有uialertaction sheet的图像选择器从相机和图库中选择图像。这段代码对我有用,所以你试试这个。并使用这些代表

- (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>**
© www.soinside.com 2019 - 2024. All rights reserved.