Using UIDocumentInteractionController Annotation Properties
I am using UIDocumentInteractionController
to share an image made in my application with another application. When you use this to share with Instagram, you can set the annotation property with a dictionary containing a key @"InstagramCaption"
that pre-populates the comment.
I would like to know if this can be done with other applications, and if so, what are the keys for the dictionary.
I'm mostly interested in doing this with the messages app and the mail app (title and body), but if you know the keys for other apps that allow you to interact with documents, that would be great too (Facebook, Twitter, WhatsApp, Path, Tumblr, ...).
That's what I'm doing:
- (void)openImageInOtherApp:(UIImage *)image
{
NSError *error = nil;
NSURL *tempDirectoryURL = [NSURL fileURLWithPath:NSTemporaryDirectory()];
NSURL *imageURL = [tempDirectoryURL URLByAppendingPathComponent:@"image.jpeg" isDirectory:NO];
NSData *imageData = UIImageJPEGRepresentation(image, 0.8);
BOOL saveSucceeded = [imageData writeToURL:imageURL options:NSDataWritingAtomic error:&error];
if (!saveSucceeded || error) {
NSLog(@"Error : Saving image %@ at URL %@ failed with error : %@", image, imageURL, error);
return;
}
UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController alloc] init];
interactionController.delegate = self;
interactionController.URL = imageURL;
NSString *comment = @"A test comment"; // A comment that will be sent along with the image
if (comment != nil && comment.length > 0) {
interactionController.annotation = @{@"someKey": comment};
}
self.interactionController = interactionController;
BOOL canOpenDocument = [interactionController presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
NSLog(@"canOpenDocument : %@", canOpenDocument ? @"YES" : @"NO");
}
Then the system view appears where I can select the application that can open the file.
source to share
Read the API developer docs (Facebook, Twitter, WhatsApp, Path, Tumblr, ...) .
Example
-
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: @"Sharing Tutorial", @"name", @"Build great social apps and get more installs.", @"caption", @"Allow your users to share stories on Facebook from your app using the iOS SDK.", @"description", @"https://developers.facebook.com/docs/ios/share/", @"link", @"http://i.imgur.com/g3Qc1HN.png", @"picture", nil];
- Tumblr API developer
This might help you :)
source to share
UIDocumentInteractionController
will not magically support all of these platforms. Some of them use an API that will give you more options.
Check out this documentation to create MMS for the Messaging app.
Use this documentation to send email with an image attached.
source to share