Friday 8 August 2014

ImageSelect to allow multiple selection in photo library via collection view interface.

Hi,
As I know , many people needs something that allow multiple  selection on iPhone Photo Library.
On lot of searching over net , I found some API that allow multiple selection on iPhone Photo Library.

But there were some disadvantages including memory warning , hanging problem etc. So to overcome this situation I introduced you a set of two files that will let you select multiple image at a time from Library.

How to Use Selector Files:-

1)First of all you need to add AssetsLibrary framework in your project.
2)Import ImageSelector.h file where ever you want to use it. And you need one more file that is check image.

  Add this image to your project and name it as check.png


3)Add its delegate as

@interface ViewController : UIViewController<ImageSelectorDelegate>
- (IBAction)select:(id)sender;
@end

 And use its delegate method in implementation file like UITableView.

4)Create object of ImageSelector File and set its delegate to self view-controller and present ImageSelector Object as modal view as given below:

    ImageSelector *selector = [[ImageSelector alloc] init];
    selector.ims_delegate = self;
    [self presentViewController:selector animated:YES completion:nil];
5)In its delegate method you will get selected Images from photo Library

-(void)ims_PickerController:(ImageSelector*)picker didFinishPickingMediaItems:(NSArray*)items
{
    [picker dismissViewControllerAnimated:YES completion:nil];

    for (UIImage *image in items) {
        NSLog(@"My Image %@\n",image);
    }
}

For File Ref ----------

ImageSelector.h

ImageSelector.m



5 comments:

  1. Hello Prince,
    I have used ImageSelecter in my project and its working fine on iPhone 5s , 6 and all the simulators but when i use it on the iPhone 6s device then the app crashes, Is it a problem with the ImageSelector
    thanks,
    Ravi Kumar

    ReplyDelete
    Replies
    1. Hi
      Sukhwinder Singh,

      I am no longer working with iOS, so as the code given you can modify it according to your will by doing some little R&D.

      Delete
  2. hi, prince i am using your code and it's working but it's works only when we have only images in our phone when we insert video in image gallery it's return nil can you help me

    ReplyDelete
    Replies
    1. You need to modify loadAssets method in order to do work with videos too. I have added filter for photos only via code piece. You need to modify it to accept video as well.

      [group setAssetsFilter:[ALAssetsFilter allPhotos]];

      You can have a look at following URL.

      https://developer.apple.com/documentation/assetslibrary/alassetsfilter?language=objc

      Delete
  3. Hi prince can you help me. The code is working fine but I have a problem with step number 3 with " And use its delegate method in implementation file like UITableView. " and how to show the selected images.

    ReplyDelete