12

When using the built in UIImagePicker from iOS the developer has access to the thumbnail image used in the picker. Is it possible to access the thumbnail used by Filepicker or otherwise access the ALAsset library URL used by Filepicker?

Kyle
  • 1,662
  • 2
  • 21
  • 38
  • As a side note the online docs state that there will be a key in the info dictionary returned from the picker that contains an ALAsset library URL, however in practice the key does not exist. – Kyle Nov 26 '12 at 16:46
  • Ahh I see there are two callbacks the first of which supplies the thumbnail image; Is there a way to access the ALAsset if that was originally the source? – Kyle Nov 26 '12 at 20:14
  • Hi Kyle. The docs have been updated to reflect the fact that only a thumbnail gets returned on the didPickMediaWithInfo call. The ALAsset will come back on the didFinishPickingMediaWithInfo call. – Liyan Chang Nov 26 '12 at 22:09
  • Liyan I never get an ALAsset library URL back from the FPPicker didFinishPickingMediaWithInfo callback, only file://location/of/my/image/in/a/tmp/dir/inside/application/bundle – Kyle Nov 27 '12 at 20:04
  • Hi Kyle. Yes. It looks like we are returning a file://... location. Can I ask why the ALAAsset library URL would be helpful? – Liyan Chang Nov 28 '12 at 19:56
  • Using the Javascript API one of the things we are able to do is collect the meta data about a particular file. If the ALAsset URL was supplied the associated meta data would be available immediately without making a second request (important for battery to try and make as few requests as possible, slower, etc...). – Kyle Nov 28 '12 at 20:33

1 Answers1

1

This how I did it, but I must warn you it is slow(ish) and frameworks needed to to this are memory intensive as it iterates over the ALAssetsLibrary looking for posterimages. This on the background thread, so UI changes are sent to the main thread for rendering.

    self.assetsLibrary = [[ALAssetsLibrary alloc] init];

    NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupSavedPhotos | ALAssetsGroupPhotoStream;
    [self.assetsLibrary enumerateGroupsWithTypes:groupTypes
                                  usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                                      if (group.posterImage != nil) {
                                          dispatch_async(dispatch_get_main_queue(), ^{
                                              self.pictureLayer.contents = (__bridge_transfer id) CGImageCreateCopy(group.posterImage);
                                              [self.layer setNeedsDisplay];
                                              self.assetsLibrary = nil;
                                              *stop = YES;
                                          });
                                      }
                                  }
                                failureBlock:^(NSError *error) {
                                    self.assetsLibrary = nil;
                                    NSLog(@"AssetLib error:%@",error);
                                }];
Steven Veltema
  • 2,140
  • 15
  • 18