Photo Picker Plus is a drop-in component that replaces the default photo picker in your app. It allows you to take a photo as well as choose a photo from the device or from several online sources. It also supports multiple selection. This tutorial will show you how to replace the default UIImagePicker in your application with Photo Picker Plus. This tutorial was written using version 5.0 of the iOS SDK and version 4.2 of Xcode. Some changes may need to be made for other software versions.
- Download the PhotoPickerPlus component and Chute SDK from https://github.com/chute/photo-picker-plus-ios
- If you don't have a Chute developer account or an app created on chute for this project then create a Chute developer account and make a new app in Chute at http://apps.getchute.com/
- For the URL you can enter http://getchute.com/ if you don't have a site for your app
- For the Callback URL you can use http://getchute.com/oauth/callback if you don't need callbacks for another purpose.
- Add the Chute SDK to the project
- Add the Photo Picker Plus component
- Link the required libraries
The next step is to enter your chute app information in the GCConfiguration.plist file. This file can be found in Resource directory in PhotoPickerPlus directory. You will need to fill in your APP ID and APP secret from the summary tab of your admin panel. If you used a custom Redirect URL when setting up your app on Chute you will also need to adjust the redirect_uri
to match the callback url you set. If you used http://getchute.com/oauth/callback
then you can leave these as they are.
At this point you may want to try running the project to make sure that everything is added ok. If it builds then everything should be correctly added and linked.
In the header for the controller that will be using the component #import "PhotoPickerViewController.h"
and inherit the PhotoPickerViewControllerDelegate
instead of the UIImagePickerDelegate
protocol.
#import <UIKit/UIKit.h>
#import "PhotoPickerViewController.h"
@interface ViewController : UIViewController <PhotoPickerViewControllerDelegate>
//existing code for your class
@end
In your class, in UIImagePickerController delegate methods, just change the class type of the picker from UIImagePickerController
to PhotoPickerViewController
. You can leave the code in these methods exactly the same as you had before because the return values are the same format.
- (void)imagePickerControllerDidCancel:(PhotoPickerViewController *)picker{
//cancel code
}
- (void)imagePickerController:(PhotoPickerViewController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//image picked code
}
- (void)imagePickerController:(PhotoPickerViewController *)picker didFinishPickingArrayOfMediaWithInfo:(NSArray *)info
{
//array of images picked code
}
Finally replace the code to display the image picker. Photo Picker Plus lets the user select a source for the image so you don't need to set it ahead of time. You will only need to specify if you want multiple selection picker or single, by setting isMultipleSelectionEnabled.
PhotoPickerViewController *picker = [PhotoPickerViewController new];
[picker setDelegate:self];
[picker setIsMultipleSelectionEnabled:NO]; // [picker setIsMultipleSelectionEnabled:YES] - for multiple choice.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (![[self popoverController] isPopoverVisible]) {
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover presentPopoverFromRect:[sender frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popoverController = popover;
}
else {
[[self popoverController] dismissPopoverAnimated:YES];
}
}
else {
[self presentViewController:picker animated:YES completion:nil];
}
You now have a multi-service photo picker in your app instead of Apple's UIImagePickerController. Most of your existing code for the imagePicker should still work because the info dictionary returned is designed to match the info dictionary returned by the UIImagePicker.