How to access iOS simulator camera [duplicate] - ios

This question already has answers here:
How do I test a camera in the iPhone simulator?
(7 answers)
Closed 8 years ago.
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];
}

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.

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.

Related

How do I solve gallery scroll stuttering in a landscape-oriented UIImagePickerController?

I have tried a couple of different methods for presenting a landscape-oriented UIImagePickerController in a landscape-only app (not by my choice) I'm working on.
When I (successfully) present the gallery in landscape format and scroll through the images, there is a truly horrible stutter!
The current technique I am using is this:
- (void)presentImagePickerController:(UIImagePickerControllerSourceType)sourceType {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if (isDeviceIPad) {
picker.modalPresentationStyle = UIModalPresentationFormSheet;
picker.preferredContentSize = [UIScreen mainScreen].bounds.size;
}
picker.sourceType = sourceType;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker
animated:YES
completion:nil];
}
I cannot go with a solution which uses private interfaces, since the app has to pass App Store review. I'd prefer not to use a third-party library, since my boss is against that idea.
My iPad is a 3rd generation, model MD334LL/A that's running iOS 8.1.
From the UIImagePickerController class reference found here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImagePickerController_Class/index.html
On iPad, the correct way to present an image picker depends on its source type, as summarized in this table:
Camera: Use full screen
Photo Library: Must use a popover
Saved Photos Album: Must use a popover
Answer: Since I want to present the Saved Photos Album, I need to present the picker by using a popover.
- (void)presentImagePickerController:(UIImagePickerControllerSourceType)sourceType {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = sourceType;
picker.delegate = self;
picker.allowsEditing = YES;
if (isDeviceIPad() && sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum) {
picker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *presentationController = picker.popoverPresentationController;
presentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
presentationController.sourceView = self.presentPickerButton;
presentationController.sourceRect = self.presentPickerButton.bounds;
}
[self presentViewController:picker
animated:YES
completion:nil];
}

How to use UIImagePickerController 's CameraOverlayView property in Simulator environment

I was working on creating a custom Camera Overlay and setting it to UIImagePickerController's CameraOverlayView property.
However since I am not enrolled in to Apple's developer program I can not really deploy and test the application package on actual device.
I also debugged my code and it appears that on Simulator you can not really choose and set imagePicker.sourceType property to the UIImagePickerControllerSourceTypeCamera. Because camera functionality is not available on simulator.
Am I right in my thinking ?
Or am I missing something and there is a way to set the CameraOverlayView property and test it on simulator ?
Here is the example of my code:
- (IBAction)takePicture:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
// Check what is possible or supported on simulator, otherwise,
//just pick from Photo library
if ( [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
if ( [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
// Allow edit
[imagePicker setEditing:YES animated:YES ];
[imagePicker setAllowsEditing:YES];
imagePicker.delegate = self;
// set custom Overlay
//imagePicker.cameraOverlayView = ( not working in simulator )
//Display the imagePicker on the screen
[self presentViewController:imagePicker animated:YES completion:NULL];
}
You are correct, the camera does not work in the iOS simulator.

Camera controls not visible on iOS 7

I have used Image Picker Controller to call device camera. The code listed below works fine below iOS 7. But when I use the Same code on iOS 7 to launch camera I am unable see "Use" and "Cancel" buttons.
- (void)getCameraPicture {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
[self presentViewController:picker animated:YES completion:NULL];
}
Any help is appreciated.
Update:
When I try to run this code in a sample app then it works fine.(sample app contains single view). But when I put it inside my project the buttons doesn't show.
in the code should be there:
...
picker.showsCameraControls = YES;
have you checked this #property (nonatomic) BOOL showsCameraControls in UIImagePickerController.

iOS6 on iPad UIImagePickerController issue

My app uses UIImagePickerContoller and it works fine with iOS 7 (iPad and iPhone) but only works on the iPhone with iOS 6. On the iPad with iOS 6 it crashes in the simulator when I click on the button that uses this class to select a picture from the photo library, but does not indicate why in the debugger log. My app is restricted to portrait view. The code is below:
-(IBAction)selectPicturePressed:(id)sender
{
//Open a UIImagePickerController to select the picture
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self.navigationController presentViewController:imgPicker animated:YES completion:nil];
}
UIImagePickerController must be presented in a UIPopoverController when the source type is the photo library.

open gallery with videos AND photos in iOS

I was using the UIImagePickerViewController, and i wanted to open the camera roll. But, in my app, i have a button to open my camera roll and another one to open my camera. When i take a picture or record a video, obviously i wanted to see those images in my camera roll. But, in my app, when i start to record a video, he doesn't show up in my camera roll's app.
Here's a little bit of code:
UIImagePickerController *cameraRoll = [[UIImagePickerController alloc] init];
[cameraRoll setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[cameraRoll setDelegate:self];
[self presentModalViewController:cameraRoll animated:YES];
At this time i can't see my videos in my camera roll's app. Could someone help me?
You just can do like this:
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker= [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
[self presentModalViewController:picker animated:YES];
}
Sets the file types you want to get on the property of the PickerViewControllerObject "mediaTypes" and you're ready.
You can found the docs types here.
Regards,
Luis

Resources