This is an iOS, Objective-C alternative to UIImagePickerController
that looks almost exactly the same, but provides the ability to select multiple images. It's as easy to setup as UIImagePickerController
and it works in both portrait and landscape orientations. It requires the addition of AssetsLibrary.framework. This code uses ARC.
Note: Using AssetsLibrary.framework will prompt users to grant access to their photos.
The easiest way to add WSAssetPickerController
to your project is via CocoaPods:
pod 'WSAssetPickerController'
Alternatively you could copy all the files in the src
directory into your project. Be sure 'Copy items to destination group's folder' is checked.
- Import the header using
#import "WSAssetPicker.h"
- Create an instance of
WSAssetPickerController
passing an instance ofALAssetsLibrary
- Implement the
WSAssetPickerControllerDelegate
protocol and set the picker's delegate - Present the
WSAssetPickerController
instance - You will also need to include the selection state
png
files:WSAssetViewSelectionIndicator.png
andWSAssetViewSelectionIndicator@2x.png
or make your own.
Check out the demo project for more details.
####Initialization and presentation
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
self.assetsLibrary = library;
WSAssetPickerController *controller = [[WSAssetPickerController alloc] initWithAssetsLibrary:library];
[self presentViewController:controller animated:YES completion:NULL];
- (void)assetPickerControllerDidCancel:(WSAssetPickerController *)sender
{
// Dismiss the WSAssetPickerController.
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)assetPickerController:(WSAssetPickerController *)sender didFinishPickingMediaWithAssets:(NSArray *)assets
{
// Dismiss the WSAssetPickerController.
[self dismissViewControllerAnimated:YES completion:^{
// Do something with the assets here.
}];
}
Note: The ALAsset
objects in the assets
array are only valid for the lifetime of the ALAssetsLibrary
instance they came from.