Post more than one photo - two UIImagePickerController's - ios

I'm having a slight issue here.
I have a basic view which has two UIButtons and two UIImageViews, I would like my users to be able to take two different photos, and these to be attached to their respective UIImageView.
Right now this works fine for the first UIButton/image, but not with a second.
.h
#interface ViewController : UIViewController <UIImagePickerControllerDelegate> {
// First button/imageview
UIImagePickerController *picker;
UIImage *image;
// Second button/imageview
UIImagePickerController *picker2;
UIImage *image2;
}
.m
-(IBAction)TakePhoto
{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:NULL];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image2 = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageField2 setImage:image2];
[self dismissViewControllerAnimated:YES completion:NULL];
}
This all works great but my question is how can I hook up the second picker to a new imagePickerController method so that my user can take two different photos on this view? I know that if I created a new action with the picker2 information it will still point to the one imagePickerController method, creating a second method and renaming this to suit does not work.
Any advice & help would be greatly appreciated.
Jamie

You don't need two UIImagePickerControllers to do it.
Take a look at takePicture method of UIImagePickerController which programatically initiates still image capture.
You can initiate additional captures after receiving imagePickerController:didFinishPickingMediaWithInfo: delegate callback.
PhotoPicker is a sample project from Apple which does exactly what you are trying to do.
Hope it helps.

Related

IOS 10 UIImagePickerController Delegate Not Being Called

I have setup the following to select an image whilst using an IPad. The problem is that the delegate never seems to get called. I've placed breakpoints in but they are never activated.
.H
#interface HomeViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
.M
- (IBAction)loadImage:(id)sender {
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePickerController.allowsEditing = NO;
self.imagePickerController.delegate = self;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
}
// This method is called when an image has been chosen from the library or taken from the camera.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//You can retrieve the actual UIImage
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
//Or you can get the image url from AssetsLibrary
NSURL *path = [info valueForKey:UIImagePickerControllerReferenceURL];
[picker dismissViewControllerAnimated:YES completion:nil];
}
Can anyone see the issue?
Thanks
if you used Xcode8 to run the project, please check the project's info.plist, make sure there is a key for "Privacy Photo library usage".
your code is right, maybe the problem is the info.plist.
I had a similar issue and it turned out that the picker was being garbage collected as soon as the image was picked, so the delegate wasn't called.
I needed to ensure that a strong reference to the picker was made before presenting it.
Once that was done, it worked fine.

how do i return an NSString or NSUrl from my didFinishPickingMediaWithInfo?

Good day, I am trying to implement the UIImagePickerController inside my selectFile function. (followed this tutorial in appcoda) but code below is a bit tweaked now based on what i want
#implementation FileBrowser
-(void)selectFile{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
NSString *myURL = [refURL absoluteString]; //not in tutorial, I'm trying to grab the url/path of the image here, with an intention of returning it to "callFileBrowser"
[picker dismissViewControllerAnimated:YES completion:NULL];
}
#end
Based on what i understood, my imagePickerController function is called when user selects an image. My question is how do i return(or get) the url instead? I have a C function on the same file (but outside #implemetation), this function calls my selectFile and is supposed to return the url/path of what the user has chosen.
char* callFileBrowser(){
[fileBrowser selectFile];
//return myURL here;
}
I hope i was able to explain everything properly. Any advice would greatly be appreciated. thanks.
I don't think it is possible with the current design. callFileBrowser() is called to pick a image, then immediately it is required to return a value. We don't know when user will be done picking, I suggest you to post a notification in didFinishPickingMediaWithInfo when the url is ready to notify other object who needs it.

UiImagePickerController - more than one photo

Iphone app, IOS 5 and up.
There are similar questions to this one on SO but I haven't encountered this exact scenario so I'll ask. I'm editing an existing app that allows lets you take a photo which it resizes and sends to a web service.
I need to add the ability to take 3 photos, resize each and send to the same service. I thought it would be just a matter of repeating what was already in the app but it uses the UIImagePickerController which apparently only allows one photo per use.
So the way it works is that there's a 'Take Photo' button which calls the method below. Once that photo is taken another button appears that says 'Take another photo' (I added this button) and I have it calling the same method but it is just copying over the previous photo, which is to be expected really. How should I best alter this to accommodate 3 photos?
This is the takephoto method that I'm calling.
- (IBAction)takePhoto:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:NULL];
}
check this https://developer.apple.com/library/ios/samplecode/photopicker/Introduction/Intro.html
, check the take photo part of this demo project.
Eventually figured out how to do this. I added a tag to the button calling the method, through IB.
Then in the takephoto method I assigned the imagePickerController a tag based on the tag of the button that tapped. Like this:
- (IBAction)takePhoto:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if([sender tag] == 2)
{
imagePickerController.view.tag = 2;
}
//And so on...
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:NULL];
}
Then in the ImagePickerController didFinishedPickingMediaWithInfo method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if(picker.view.tag == 2)
{
//Do stuff here
}
}
So, I'll probably have to create three different buttons for each of the three possible photos, I'm sure there's a better way than that but it should work.

How to detect UIImagePickerController Preview state?

I use standart image picker to make some camera photo.
When user makes photo image picker shows him the Preview screen with 2 buttons "Retake" and "Use".
How to detect that Preview screen is active now or "Retake" button pressed? Is it possible ? Are the useful properties or events? Something like when image source is library the is property - allows editing, which shows similar screen .
UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
A bit after the fact, but maybe someone is still seeking this answer like I was. If you want continue using the native camera controls, you can check the subviews of the ImagePickerController to determine if the post-record view is showing.
BOOL videoTaken = NO;
for (UIView *aView in self.imagePickerController.view.subviews[0].subviews[0].subviews[0].subviews)
{
if ([aView isKindOfClass:NSClassFromString(#"PLTileContainerView")])
{
videoTaken = YES;
break;
}
}
The "PLTileContainerView" is the subview that contains the editing slider that lets you view your video frame by frame, so if it's present, that means your video has already recorded.
For use:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:NO];
NSString *type = [info objectForKey:#"UIImagePickerControllerMediaType"];
if ([type isEqualToString:#"public.movie"]) {
} else {
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
}
For Cancel you don't have a way of detecting it (other than subclassing UIImagePickerController, which may be prohibited, or other way that I'm not aware), but for sure the second cancel is detectable :
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}

iPad UIImagePicker Problem !

iam trying import an image from photos library but when i press the import button program crashes and received SGIBART !! but my code works fine on iPhone why ?
here is my code :
.h :
#interface CameraViewController : UIViewController <UIImagePickerControllerDelegate ,UINavigationControllerDelegate> {
UIImagePickerController *ipc;
UIImageView * image1;
#property (.......................;
}
.m :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image1.image = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
[[picker parentViewController]dismissModalViewControllerAnimated:YES];
[picker release];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[[picker parentViewController]dismissModalViewControllerAnimated:YES];
[picker release];
}
-(IBAction) importImage1 {
ipc = [[UIImagePickerController alloc]init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:ipc animated:YES];
}
You're crashing because you're releasing picker, but you didn't retain it. You should remove the calls to [picker release].
You should switch to using accessors for all of your ivars. Accessors and dealloc are generally the only places you should retain or release your ivars. picker is not your ivar and you didn't create it, so you shouldn't be releasing it at all.
You should spend some time with the Memory Management Programming Guide. You can get the short version at Three Magic Words.
On the iPad iOS 3.2 a UIImagePickerController must be presented in a popover, not as a modal view.
check this out :
http://www.cocos2d-iphone.org/forum/topic/6108

Resources