ios - 调用相机时代码崩溃

标签 ios iphone camera

这是我的代码:

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        UIImagePickerController *picker=[[UIImagePickerController alloc] init];
        picker.delegate=self;
        picker.sourceType=UIImagePickerControllerSourceTypeCamera;
        picker.allowsEditing=YES;
        [self presentViewController:picker animated:YES completion:nil];
    }

PS: "sourceType = UIImagePickerControllerSourceTypePhotoLibrary " 可以的。 "sourceType = UIImagePickerControllerSourceTypeCamera " 错了

这是我得到的错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x21f1949f 0x2f700c8b 0x21e39873 0x21e39657 0x2544bbc3 0x2544b815 0x253e4d67 0x2aa06681 0x253d924f 0x24e01a0d 0x24dfd3e5 0x253eb987 0x26bd5fa5 0x26bd13b3 0x26bd2429 0x26bcbad9 0x2aa03cb5 0x2a9d1b53 0x253f151b 0x2548528f 0x25484d63 0x256cba3f 0x256caf87 0x254f92cf 0x256ca81f 0x256bc6df 0x254f919d 0x2561fb1b 0x2561f9f3 0x253f151b 0x256a7c8d 0x25455a25 0x253d182b 0x21edfd95 0x21edd453 0x21edd85b 0x21e2b3c1 0x21e2b1d3 0x291e90a9 0x2543afa1 0x1d1a65 0x2fc80aaf)

我能得到一些帮助来解决这个问题吗?

最佳答案

-(void)actionLaunchAppCamera
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.allowsEditing = YES;

        [self presentModalViewController:imagePicker animated:YES];
    } else {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Camera Unavailable"
            message:@"Unable to find a camera on your device."
            delegate:nil
            cancelButtonTitle:@"OK"
            otherButtonTitles:nil, nil];
        [alert show];
        alert = nil;
    }
}

关于ios - 调用相机时代码崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27436518/

相关文章:

ios - 我是否需要包含整个 SDWebImage 库以在 UICollectionView 中下载图像?

ios - 如何在swift3中用其他元素替换数组的值?

Android相机 Intent : how to get full sized photo?

Android - 相机预览

ios - 更改自定义 MKAnnotation 数据后如何更新自定义 MKAnnotationView?

iOS:收到 `304 Not Modified` 响应时 AVPlayerItem 中的错误

ios - Alamofire 使凭证无效

iphone - 我们如何在没有付费 iOS 开发者帐户的情况下测试相机应用程序?

iphone - 旋转拨号器,如iPhone中的iRetro拨号器动画

c++ - Gstreamer 通过 RTP 流式传输多个摄像头,同时保存每个流