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

时间:2018-02-06 13:00:33

标签: ios objective-c ios-camera

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

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

我的代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class rotateYAxis : MonoBehaviour {

    private bool shouldRotate = false; //should not rotate at the beginning

    // Update is called once per frame
    void Update() {
        if (Input.GetKeyDown(KeyCode.Alpha0)) {
            shouldRotate = !shouldRotate; //changing true to false and false to true
        }
        if (shouldRotate) {
            transform.RotateAround(transform.position, (Vector3.up), Time.deltaTime * 90f);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

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

- (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>**