I am using UIDocumentInteractionController to share an image taken in my app with an other application.
When you use this to share with Instagram, you can set the annotation property with a dictionary containing the key @"InstagramCaption", which will pre-fill the comment.
I would like to know if it is possible to do this with other applications, and if so what are the keys for the dictionary.
I'm mainly interested to do this with the messages app and the mail app (title and body), but if you know the keys for other apps that allow document interaction it would be great too (Facebook, Twitter, WhatsApp, Path, Tumblr, ...).
Here is what I do :
- (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 choose an app that can open the file.
Read API developer documents(Facebook, Twitter, WhatsApp, Path, Tumblr, ...).
Example
API developer facebook
// 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];
API developer twitter
This might helps you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With