How to access photo library for ipad apps - ipad

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

Related

iOS 14 - Thumbnails do not display in the UIImagePickerController

Thumbnails do not display in the UIImagePickerController when running on iPhone 11 or real device with iOS 14.
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate=self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:picker animated:YES completion:nil];
Result:
Photos and Albums showing as Blank but when I tap on-screen image will be selected.
For me, it was caused by using
UIScrollView.appearance(whenContainedInInstancesOf: [UINavigationController.self]).backgroundColor = .backgroundPrimaryNew
I don't know why is that, but after I've removed this line it began working again and thumbnails are showing.
Try this
Instead of presenting add UIImagePickerController as subView
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate=self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self.view addSubview:self.picker.view];
[self addChildViewController:self.picker];
[self.picker didMoveToParentViewController:self];

full screen camera in ios

I'm using the following code so the user can take a pic:
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
Is there a way to make the camera occupy the hole screen?
What you're seeing is the default implementation of UIImagePickerController which includes camera controls.
Try turning these off by setting showsCameraControls to NO.
If you want to add your own controls, use cameraOverlayView.

shouldAutorotateToInterfaceOrientation in ios6

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.

How to Make UIImagePicker full screen with popover controller for ipad

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.

Test ipad 2 camera with xcode simulator IOS 5

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

Resources