157

I am making a camera app. I need to test the app in the simulator but I can't access the iOS simulator camera.

If not possible in the simulator means I need to access my system camera. Whether it is possible?

I tried UIImagePickerController but it doesn't work.

The below the code I've tried.

self.imagePicker = [[UIImagePickerController alloc] init];  
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.usingPopover = YES;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
sourceType = UIImagePickerControllerSourceTypeCamera;
self.usingPopover = NO;
}
[self.imagePicker setSourceType:sourceType];
self.imagePicker.allowsEditing = NO;
self.imagePicker.delegate = self;
if (sourceType != UIImagePickerControllerSourceTypeCamera) {
self.popover = [[UIPopoverController alloc] initWithContentViewController:self.imagePicker];
self.popover.delegate = self;
[self.popover presentPopoverFromRect:popoverFrame inView:self.view  
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self presentModalViewController:imagePicker animated:YES];    
}
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
R M
  • 1,741
  • 2
  • 10
  • 6

2 Answers2

230

It's not possible to access the camera of your development machine to be used as the simulator camera. Camera functionality is not available in any iOS version and in any Simulator. You will have to use a real device for camera testing purposes.

Salman Zaidi
  • 9,342
  • 12
  • 44
  • 61
  • 85
    Wow, that's pathetic, Apple. And this was never changed since 2014 either? – Joel Roberts Jun 09 '22 at 00:38
  • 18
    Apple is really stupid with this notion, Android's simulator allows me to either use my webcam or just offer a simulated image, you guys can't come up with that and instead ask me to use a real device? Just shows it's all about money and not developers when it comes to Apple. – Eman Jul 26 '22 at 14:35
  • 9
    I should stop getting surprised by Apple making developers' lives hard. But I still get caught off-guard every time. – BoltKey Aug 17 '22 at 18:57
  • 2
    wasted a day pro max plus ultra on this. thank you for clarifying this and now I need to get a used device. – Shehroze Malik Nov 02 '22 at 05:36
  • 4
    Until now, I still can't believe this. Good job apple, keep going.. haha – O Thạnh Ldt Jan 28 '23 at 01:54
  • 1
    lool I really can't believe this, is 2023, how in the earth is possible to that you have to pass over all their process to export the app (which is super hard) to simply test your camera ? – Alejandro Giraldo May 20 '23 at 03:16
86

Simulator doesn't have a Camera. If you want to access a camera you need a device. You can't test camera on simulator. You can only check the photo and video gallery.

neaumusic
  • 10,027
  • 9
  • 55
  • 83
Chetan
  • 2,004
  • 1
  • 13
  • 21