UIImagePickerController,Check camera

-(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];
    }

I want to put out an alert when you do not have a camera.
IPhone app launch and move in this code.
But, Crash (This Error >

return UIApplicationMain(argc, argv, nil, NSStringFromClass([CameraAppDelegate class])); > Thread 1: signal SIGABRT) when run in a simulator.

  • How to call a method of super.super?
  • Appium on real iOS devices
  • Subtract 7 days from current date
  • How to calculate time in hours between two dates in iOS
  • Handling Push Notifications when App is Terminated
  • Xcode items greyed out in the Document Outline
  • Why is this?

    2 Solutions Collect From Internet About “UIImagePickerController,Check camera”

    use this code and add UIImagePickerControllerDelegate delegate in .h file

     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];
    
        }
    

    Create NSObject Class and name it like ClsGlobal, or the name you want..

    then write +(BOOL)isCameraDeviceAvailable in your ClsGlobal.h and implement below function in ClsGlobal.m.

    +(BOOL)isCameraDeviceAvailable
    {
        BOOL isCameraAvailable=NO;
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
                isCameraAvailable = YES;
        }
        return isCameraAvailable;
    }
    

    Use this class method, It will return YES if camera available else return NO.

    Now you can call this method using [ClsGlobal isCameraDeviceAvailable]; means your if Condition looks like if([ClsGlobal isCameraDeviceAvailable]).

    This method will help you throughout your project in any controller, You have to just import ClsGlobal like #import "ClsGlobal.h".