2

I have a share extension that supports images. Everything is working and I get the image from the item provider like so:

if([imageItemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeImage])
{
    [imageItemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeImage options:nil completionHandler:^(UIImage *image, NSError *error)
     {
         if(image)
         {
             // do smth with the image here
         }
     }];
}

The issue is I'd like to access the image info via ALAssetsLibrary, and I don't have its URL since the loadItemForTypeIdentifier returns an UIImage directly. Any idea how to grab the image URL?

Jacob K
  • 2,669
  • 1
  • 15
  • 20

1 Answers1

10

Change [imageItemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeImage options:nil completionHandler:^(UIImage *image, NSError *error)

to

[imageItemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeImage options:nil completionHandler:^(NSURL *url, NSError *error)

Notice the completion handler argument type. This will return to you the url that you are looking for.

JVillella
  • 1,029
  • 1
  • 11
  • 21
  • 1
    Ok this is crazy magical. When I first saw this I thought no way but it was uprooted, and the documentation confirms this as does using it. They're either doing some runtime inspection on the block or compiler voodoo. – Aaron Zinman Feb 05 '15 at 02:28
  • It's really cool! That's for sure, but not hard to implement. [Introspection](https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaEncyclopedia/Introspection/Introspection.html) by way of [NSObject isKindOfClass:] is one such solution. – JVillella Feb 05 '15 at 13:57