UIIMagePicker on iPad to view photoLibrary crash - ios

Im trying to get my imagePicker to load photos from my sourceLibrary. With the following code the app crashes with the following message 'Application tried to present modally an active controller'
-(void)viewPhotoLibrary{
NSLog(#"get photos");
UIImagePickerController *imagePickerController =
[[UIImagePickerController alloc] init];
UIPopoverController *pop = [[UIPopoverController alloc]
initWithContentViewController:imagePickerController];
pop.delegate = self;
[pop setPopoverContentSize:CGSizeMake(500, 500)];
[pop presentPopoverFromRect:
CGRectMake(0, 0, 500, 500)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePickerController setDelegate:self];
[imagePickerController setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:imagePickerController animated:YES completion:nil];
}

comment the code
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePickerController setDelegate:(id)self];
[imagePickerController setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:imagePickerController animated:YES completion:^{
}];
or use this code
-(void)viewPhotoLibrary{
NSLog(#"get photos");
UIImagePickerController *imagePickerController =
[[UIImagePickerController alloc] init];
UIPopoverController *pop = [[UIPopoverController alloc]
initWithContentViewController:imagePickerController];
pop.delegate = self;
[pop setPopoverContentSize:CGSizeMake(500, 500)];
[pop presentPopoverFromRect:
CGRectMake(0, 0, 500, 500)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}

Related

UIImagePickerController in UINavigationController

Guyz, I am displaying UIImagePickerController in UINavigationController but some frame of image picker controller hides under nav bar .Do any Body has the solution and code is
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
//[picker.view setFrame:CGRectMake(0,50, 800, 600)];
self.nv=[[UINavigationController alloc]init];
[self.nv.view setFrame:(CGRectMake(0, 50, 320.0, 400.0))];
// 4. add the nav bar to the main view
[self.nv addChildViewController:picker];
[picker didMoveToParentViewController:self.nv];
picker.view.frame = CGRectMake(15, 50, 290, 400);
popoverController = [[UIPopoverController alloc] initWithContentViewController:self.nv];
[popoverController presentPopoverFromRect:[(UIButton *)sender frame]
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
Try this alternate. :)
#define ISIPHONE [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone
UIPopoverController *popover;
- (IBAction)openImagePicker:(UIButton *)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //UIImagePickerControllerSourceTypeCamera
if (ISIPHONE)
{
[self presentViewController:picker animated:YES completion:NULL];
}
else
{
if (!popover)
{
popover = [[UIPopoverController alloc] initWithContentViewController:picker];
}
[popover presentPopoverFromRect:sender.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}

how to load Video from ipad library in ipad app

I have an iPad app in which when I click on the button it opens a popover with the iPad library to see the photos and pics. I want that when I click the button it should also show video in that but it does not show videos.
In device when I see library it shows videos but when popover opens in app it does not show any video.
UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
pckrImage.delegate = self;
if (isiPhone) {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pckrImage animated:YES];
}
}
else {
popOver = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
[popOver presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
First Create normal popover then add this code to for button 'choose photo from gallery'
UIImagePickerController *imagePicker1 = [[UIImagePickerController alloc] init];
imagePicker1.contentSizeForViewInPopover=CGSizeMake(300, 200);
imagePicker1.delegate = self;
imagePicker1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
Popcontroller = [[UIPopoverController alloc] initWithContentViewController:imagePicker1];
[Popcontroller presentPopoverFromRect:cell1.ButtonAddPicture.frame
inView:cell1.ButtonAddPicture.superview
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
and for video add following line to above code
imagePicker1.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];

UIImagePickerController with PopOver not working on iPad Device

I am using the UIImagePickerController for picking the image and use the image in ipad application it works fine on simulator but it does not open imagepickerController in device here is my code
else if([labelType.text isEqualToString:#"Select Image"]){
selectedType=#"Select Image";
BOOL isiPhone;
UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
pckrImage.delegate = self;
if (isiPhone) {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
{
pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pckrImage animated:YES];
}
else {
}
}
else
{
popOver = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
[popOver presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
Please make change as
UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
pckrImage.delegate = self;
if (isiPhone) {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
{
pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:pckrImage animated:YES];
}
else {
}
}
else
{
UIPopoverController *popOver = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
self.popoverImageViewController = popOver;
[self.popoverImageViewController presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
Initialize the object
#property (strong,nonatomic) UIPopoverController *popoverImageViewController;
Try this:
UIImagePickerController *pckrImage = [[UIImagePickerController alloc] init];
pckrImage.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
pckrImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (isiPhone) {
[self presentModalViewController:pckrImage animated:YES];
}
else
{
popOver = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
[popOver presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
Hope this helps.
Try to present the popover with UIPopoverArrowDirectionAny.
[self.popoverController presentPopoverFromRect:CGRectMake(450.0f, 825.0f, 10.0f, 10.0f)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];

Popover not showing iPad photo library

I am trying to write an app that will allow the user to select an image from the photo library on the iPad. I have done exactly as sources online say it should be done, however when I click the button only the arrow is showed on screen and nothing else. The popover which should show with the images does not show. Could anyone please tell me why this is happening? Here is my code:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[picker setDelegate:self];
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[picker setAllowsEditing:YES];
popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];
[popoverController presentPopoverFromRect:self.view.frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
I know it is to to late to answer but if you're already interested on it, this may work for you:
In the .h file, gives this delegates:
#interface ViewController : UIViewController <UIPopoverControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate>
create the popover as a property:
#property (nonatomic, strong) UIPopoverController *popoverController;
and finally in the .m file:
-(IBAction)showPhotoLibray:(id)sender
{
BOOL hasGellery = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = hasGellery ? UIImagePickerControllerSourceTypePhotoLibrary : UIImagePickerControllerSourceTypePhotoLibrary;
if (self.popoverController != nil)
{
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController=nil;
}
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];
CGRect popoverRect = [self.view convertRect:[self.theViewObject frame]
fromView:[self.theViewObject superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 300) ;
popoverRect.origin.x = popoverRect.origin.x;
[self.popoverController
presentPopoverFromRect:popoverRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
the self.theViewObject is an outlet of the object view controller that is calling the method, for example an UIButton

How to increase Size of popOverView in iPad?

I ma Using Following code to pop photo library in ipad..
[[UIImagePickerController alloc] init];
videoPicker.delegate = self;
videoPicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
videoPicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,(NSString *)kUTTypeMovie,nil];
videoPicker.allowsEditing = YES;;
pop = [[UIPopoverController alloc]initWithContentViewController:videoPicker];
[pop setDelegate:self];
[pop presentPopoverFromRect:[sender frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
[videoPicker release];
How to increase the size of popOverView in this?
The popoverContentSize property controls the size of the popover content view.

Resources