UIImagePickerController,检查相机

oni*_*ion 5 iphone xcode uiimagepickercontroller ios

-(void)viewDidLoad
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
   {
      imagePicker = [[UIImagePickerController alloc] init];
      imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
      imagePicker.showsCameraControls = NO;
      [self.view addSubview:imagePicker.view];
      }
      else
      {
      // UIAlertView…
      }
}

    -(void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        imagePicker.delegate = self;
        [self presentViewController:imagePicker animated:NO completion:NO];
    }
Run Code Online (Sandbox Code Playgroud)

我想在你没有相机的时候发出警报.iPhone应用程序启动并移动此代码.但是,崩溃(此错误>

return UIApplicationMain(argc, argv, nil, NSStringFromClass([CameraAppDelegate class])); > Thread 1: signal SIGABRT) 在模拟器中运行时.

为什么是这样?

Par*_*shi 8

使用此代码并UIImagePickerControllerDelegate.h文件中添加委托

 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])  
    {
       UIImagePickerController* picker = [[UIImagePickerController alloc] init];
       picker.sourceType = UIImagePickerControllerSourceTypeCamera;
       picker.delegate = self;
      picker.wantsFullScreenLayout = YES;
      [self presentModalViewController:picker animated:YES];
    }
    else
    {
        UIAlertView *altnot=[[UIAlertView alloc]initWithTitle:@"Camera Not Available" message:@"Camera Not Available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        altnot.tag=103;
        [altnot show];
        [altnot release];

    }
Run Code Online (Sandbox Code Playgroud)