Reputation: 5563
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.
Upvotes: 3
Views: 2177
Reputation: 2634
The UIDocumentInteractionController
is not going to magically support all of those platforms. Some of those use an API which will provide you with more options.
Take a look at this documentation for creating a MMS for the Messages app.
Use this documentation for sending an email with an image attachment.
Upvotes: 0
Reputation: 2527
Read API developer documents(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];
This might helps you :)
Upvotes: 1