UIImagePickerController with PopOver not working on iPad Device - ios

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

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

Dismiss a imagepickercontroller

I'm trying to dismiss a imagepickercontroller (album or camera) which is presented as below
[self.view.window.rootViewController presentViewController:imagePicker animated:YES completion:nil];
By calling :
[self dismissViewControllerAnimated:YES completion:NULL];
I can't dismiss the imagepickercontroller.
Any body can help me on this?
I use this:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
[self dismissViewControllerAnimated:YES completion:nil];
else
[popover dismissPopoverAnimated:YES];
Don't know whether the NULL rather than nil would matter, but it should be nil.
The picker is presented with the following code:
- (void)getVideoFromDevice
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // for ipad only
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = NO;
imagePicker.videoQuality = UIImagePickerControllerQualityTypeLow;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];;
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromBarButtonItem:[self.navigationItem.rightBarButtonItems objectAtIndex:0] permittedArrowDirections: UIPopoverArrowDirectionAny animated:YES];
}
else // for iphone only - NOT TESTED
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
I haven't tested the code for iPhone yet but the iPad portion is working correctly.
You need to dismiss the UIImagePickerViewController in the delegate methods: imagePickerController: didFinishPickingMediaWithInfo: and imagePickerControllerDidCancel:. Just be sure to assign the UIImagePickerViewController delegate to the UIViewController that presents the UIImagePickerViewController.
Example:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{
[picker dismissViewControllerAnimated:YES completion:nil];
}

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

UIIMagePicker on iPad to view photoLibrary crash

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

UIPopoverController crash on iPad running iOS 5.0.1?

I am using a UIImagePickerController on iOS 5 with the iPad and my app just got rejected because it crashed on their end. It doesn't crash on my end but I am sure it has to do with the UIPopoverController.
Please just point anything out that looks bad!
To show the UIImagePickerController:
- (IBAction)photoLibraryiPad {
if (popoverController) {
if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];
[popoverController setDelegate:nil];
[popoverController release];
}
} else {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = YES;
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:imagePicker];
popoverController.delegate = self;
[self.popoverController presentPopoverFromRect:photolibrarybutton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[imagePicker release];
}
}
}
Then this is where it is crashing on their end:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];
[popoverController setDelegate:nil];
[popoverController release];
}
[noimageAvailable setHidden:YES];
UIImage *originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
[imgPic setImage:originalImage forState:UIControlStateNormal];
// Hide picker selector
[picker dismissModalViewControllerAnimated: YES];
[picker release];
}
Two things:
1) When you release the popover, you should set the delegate to nil. popoverController.delegate = nil before calling [popoverController release]. Chances are if you try to use the picker multiple times, it will crash for you too. The delegate is calling an object that no longer exists.
2) When checking to see if the popover is visible, check to make sure it exists first.

Resources