How to use UIImagePickerController properly on the iPad? - iphone

From the documentation of UIImagePickerController:
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.
So what they say is:
On iPad I MUST use a UIPopoverController to display the image picker.
But at the same time, it is limited to UIImagePickerControllerSourceTypeCamera
How about the other source types such as UIImagePickerControllerSourceTypePhotoLibrary or UIImagePickerControllerSourceTypeSavedPhotosAlbum?
In my case I want the user to choose from his photo library and not take a picture with the camera.
Is there a way to use UIImagePickerController to pick photos from a library on the iPad?

I suspect that documention has a typo in it. I've successfully used UIImagePickerController with other sourceTypes on iPad - just had to make sure it was in a UIPopoverController.

Related

uibarbutton and popoverview on iPhone

I am looking for a great tutorial to implement a popoverview on iPhone all I found so far is talking about the ipad or is crashing
You cannot implement the UIPopover in iPhone.
Please refer UIElementGuidelines
For a nice popover tutorial check this site.
For popover in iPhone use the following Open source controls:
FPPopover
ModalView in iPhone
KGModal
MJPopupviewcontroller
UAmodalpanel
RNBlurmodalview
For more check this site
you cannot implement the standard popoverview in iphone. Have to make a custom view that replicate the popoverview.
Check these :
http://www.50pixels.com/blog/labs/open-library-fppopover-ipad-like-popovers-for-iphone/
This May help you great sample code you can find
https://github.com/takashisite/TSPopover
https://github.com/kyoshikawa/ZPopoverController
https://github.com/ddebin/DDPopoverBackgroundView
https://github.com/werner77/WEPopover

iPhone How to present photos from my documents directory?

I have been using UIImagePicker controller for taking photos and saving it to my documents directory. Now i want to be able to present them to user for picking. UIImagePicker has neat functionallity
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
When I set this property all images from library are presented. Is there some way I can use UIImagePicker to present my photos from documents directory?
The only supported sources for the UIImagePicker are library, camera or saved photo album. See UIImagePickerControllerSourceType # http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
enum {
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
};
typedef NSUInteger UIImagePickerControllerSourceType;

What are the methods/classes I need to create an iPhone upload photo form?

Currently I have a view with an ImageViewer and 2 buttons (Browse & Upload). I'm currently searching for methods to display the iPhone photo album once the button is pressed.
I've looked at this example here but I assume this one is the method you call when you want to upload the photo into the server.
Objective C: How to upload image and text using HTTP POST?
I'd like to duplicate the functionality of a web upload form.
1. Click button to browse folders.
2. Choose photo and display in a container.
3. Click Upload to upload photo into the server.
**Update:
Found some nice tutorials that helped me start with my iPhone app photo upload form.
Using UIImagePickerController
http://iosdevelopertips.com/camera/camera-application-to-take-pictures-and-save-images-to-photo-album.html
http://trailsinthesand.com/picking-images-with-the-iphone-sdk-uiimagepickercontroller/
Adding images to iPhone Simulator
You will have to use UIImagePickerController class
Here is the class reference for UIImagePickerController
Initialize the picker controller in your button event handler method.
Then set the UIImagePickerControllerDelegate to your current viewController
Here is the class reference for UIImagePickerControllerDelegate
picker.delegate = self;
Set the UIImagePickerControllerSourceType of picker to UIImagePickerControllerSourceTypePhotoLibrary
picker.UIImagePickerControllerSourceType = UIImagePickerControllerSourceTypePhotoLibrary
Then present the pickerViewController (if your target device is an iPad, present the imagePickerView in a popOver control)
Once user selects an image picker controller will automatically call its delegate method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
You can get the selected image by accessing the value for UIImagePickerControllerOriginalImage from the NSDictionary *info
Then you can use the image for uploading to server as mentioned in the post link
These are some tutorials for UIImagePickerController
Tutorial one
Tutorial two
Tutorial three
for getting images from iPhone library you have to use UIImagePickerController.
m_imagePickerController = [[UIImagePickerController alloc] init];
m_imagePickerController.delegate = self;
m_imagePickerController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
hope this will help you

Must I save the captured image to the Camera Roll when using UIImagePickerController with source type camera?

From the docs of UIImagePickerController:
When the user taps a button to pick a newly-captured or saved image or
movie, or cancels the operation, dismiss the image picker using your
delegate object. For newly-captured media, your delegate can then save
it to the Camera Roll on the device. For previously-saved media, your
delegate can then use the image data according to the purpose of your
app.
So this reads like I MUST save the captured image to the Camera Roll. Is this true? Reason for rejection if not done?
No, you do not need to save to Camera roll when UIImagePickerController is dismissed. I have done this in several apps.

UIImagePickerControllerSourceTypeCamera crashes in IPHONE Simulator?

Is it a known issue that if you try to test your UIImagePickerController using the Camera as a source type then the simulator will crash?
I have the following code:
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
[self.imgPicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:self.imgPicker animated:YES];
[imgPicker release];
Running this in simulator, I get an objc-exception-throw error on the stack # -[UIImagePickerController setSourceType:].
Now if I set the source type to the Photo Library though, everything runs smoothly and fine? What's the deal?
Simulator doesn't have the camera and can't simulate to take a picture (it would have been nice to use the isight but Apple has not been so kindly). However Your code is not safe because, for example, old ipod touch doesn't have a camera and in this case your app will crash on this device.
As Apple suggest in UIImagePickerController documentation:
To use an image picker controller
containing its default controls,
perform these steps:
1.Verify that the device is capable of picking content from the
desired source. Do this calling the
isSourceTypeAvailable: class method,
providing a constant from the
“UIImagePickerControllerSourceType”
enum.
2.Check which media types are available, for the source type you’re
using, by calling the
availableMediaTypesForSourceType:
class method. This lets you
distinguish between a camera that can
be used for video recording and one
that can be used only for still
images.
3.Tell the image picker controller to adjust the UI according to the
media types you want to make
available—still images, movies, or
both—by setting the mediaTypes
property.
4.Present the user interface by calling the
presentModalViewController:animated:
method of the currently active view
controller, passing your configured
image picker controller as the new
view controller.
5.When the user taps a button to pick a newly-captured or saved image
or movie, or cancels the operation,
dismiss the image picker using your
delegate object. For newly-captured
media, your delegate can then save it
to the Camera Roll on the device. For
previously-saved media, your delegate
can then use the image data according
to the purpose of your app.
So you have to call isSourceTypeAvailable and set your sourceType consistently.