I am sure this is trivial once someone kindly point me in the right direction so my apology for asking a silly question. However I have been searching for days I can't figure out what I am doing wrong.
Scenario: create a simple share extension that receive an image file
Problem: when I access the attachements, I get no data back.
What I have done:
1) added the same group to both app and app extension
2) made sure both have the group (1) in the entitlement
3) made sure both are using a certificate/app id with that group enabled
4) clean and rebuild several times to no avail.
The code:
- (void)didSelectPost {
/
for (NSExtensionItem *item in self.extensionContext.inputItems) {
for (NSItemProvider *itemProvider in item.attachments) {
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeImage]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeImage options:nil completionHandler:^(UIImage *image, NSError *error) {
if (error!=nil){
errorMsg = error.description;
}
photo = image;
}];
break;
}
}
}
NSLog(errorMsg);
.... and so on and so forth
I can place a break point and see that loadItemForTypeIdentifier get called but the photo object is always nil and so is the errorMsg. Help, please?
A common reason you may not see an image from a share extension is that the code in the block may not have finished as execution passes on to the next stage.
In my case I was trying to send the file in an email. I found my code worked with small images, like icons (that had loaded in time) but was blank with larger photos.
I posted the solution I used here, on Stack Overflow, if that is any help.
http://stackoverflow.com/questions/32456738/why-do-larger-images-not-appear-in-a-share-extension-or-action-extension-solve/32456739#32456739