I am testing ipad camera application with ipad simulator
I used below code, change the source type instead of camera.
-(IBAction)useCamera:(id)sender{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate =(id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>) self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
newMedia = YES;
}
}
When it run in the simulator error came up in ios 5 simulator .
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'On iPad, UIImagePickerController must be presented via UIPopoverController'
But its working on 4.3 simulator
Starting with iOS5 you need to show the pickercontroller in a popover view rather than a modal view.
From the apple documentation: On iPad, present the user interface using a popover. Doing so is valid only if the sourceType property of the image picker controller is set to UIImagePickerControllerSourceTypeCamera. To use a popover controller, use the methods described in “Presenting and Dismissing the Popover” in UIPopoverController Class Reference.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
Here is an example of presenting a UIImagePickerController inside a popover view:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
Related
This is my code to present the UIImagePickerController:
UIImagePickerController *imagepicker = [[UIImagePickerController alloc] init];
imagepicker.delegate = self;
imagepicker.view.backgroundColor = [UIColor orangeColor];
UIImagePickerControllerSourceType sourcheType = UIImagePickerControllerSourceTypePhotoLibrary;
imagepicker.sourceType = sourcheType;
imagepicker.allowsEditing = YES;
[self presentViewController:imagepicker animated:YES completion:nil];
This is the image where the error occurred
This is a normal picture
This happens on one iPad (iOS 11.1.2), but it works fine on the other (iOS 8.4.1). I tried the changes, but none seemed to work.
I am showing the camera in a popover (on an iPad - the iPad app is locked to Lanscape Left) and the preview is in Portrait and the wrong scale. The code is below - I have worked out the rotation and added it, but the preview size is the too thin now.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.videoQuality = UIImagePickerControllerQualityTypeMedium;
imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
CGAffineTransform transformRotation = CGAffineTransformMakeRotation(270 * M_PI/180);
imagePicker.cameraViewTransform = transformRotation;
}
else
{
NSLog(#"Camera not available. Using photo library");
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
imagePicker.delegate = self;
_photoPopover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[_photoPopover presentPopoverFromRect:view.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Turns out to be an issue with the way iOS 6.0 deals with rotation - its fixed in 6.1
I think this is the solution for ur question so u can follow the code as per this link provided below.
UIImagePickerController in Landscape
It will helps u a lot.Enjoy the coding.
I am using UIImagePickerviewController to open the photo library through the below attached code... after called bit lines of code. The application was crashed... Its working fine in ios5
UIImagePickerController* content = [[UIImagePickerController alloc] init];
content.delegate = self;
content.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:content animated:YES];
[content release];
Is anything wrong with this code?
Check Crash on presenting UIImagePickerController under ios6 You will get everything you need to make UIImagePickerviewController working on iOS 6.0.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:cameraButton.frame inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
else{
[self presentModalViewController:imagePicker animated:YES];
}
I had the same issue. Because the UIImagePicker shows on portrait mode.
I fixed it by subclassing the UIImagePicker and implementing the shouldAutorotate method like:
- (BOOL)shouldAutorotate
{
return NO;
}
I have created instance of my subclassed imagePicker instead of UIImagePicker, everything worked fine. Hope this will help you.
I have seen other posts on this subject, but no valid solutions. Surely this is possible! I found one solution here that suggests presenting it from a container view controller. The code for that is commented out in my method below. This DOES create the fullscreen view, but the cancel/take photo buttons won't work then, and I can't seem to dismiss it properly. Is there really no simple elegant solution to this???? Please help! Here's my code:
-(IBAction)launchCamera:(id)sender
{
[self.popoverController dismissPopoverAnimated:YES];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//fullScreenViewController = [[UIViewController alloc] init];
//fullScreenViewController.contentSizeForViewInPopover = CGSizeMake(768, 1024);
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Tried making the view full screen (or at least larger), but doesn't work...
//popoverController.contentViewController.contentSizeForViewInPopover = CGSizeMake(384, 512);
[imagePicker setTitle:#"camera"];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
imagePicker.delegate = self;
imagePicker.allowsEditing = NO;
//[fullScreenViewController.view addSubview:imagePicker.view];
// change imagePicker to fullScreenViewController here for full screen:
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popoverController setDelegate:self];
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
I never could make the UIImagePicker work properly in full-screen, so I ended up using the AVFoundation framework to implement my own.
I am facing a problem when I try to access the photo library when developing iPad apps. However, the same code works properly for iPhone dev. The error which is generated is:
On iPad, UIImagePickerController must be presented via UIPopoverController
I am using the following code for iPad development:
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
Try presenting with a pop over controller in iPad, doesn't support modal view controller
even I encountered the same problem, so tried using pop over controller and it works now :)
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
popControl = [[UIPopoverController alloc]initWithContentViewController:picker];
popControl.delegate=self;
[popControl presentPopoverFromRect:browseButton.bounds inView:mainView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];