Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook send dialog in iOS app

I have an iOs app in which I tell the user to share a link with the friends he wants. I want to offer him the possibility to open a new inbox from within the app and if possible with pre-filled content. But no pre-filled recipient. And I want it to be available to all users (not only those with facebook connect).

Basically I want to replicate the following send dialog for web in the app: https://developers.facebook.com/docs/reference/dialogs/send/

Which means it will open the facebook app and not the browser to show the new inbox dialog.

From my research I found no clear solution and as it is possible from a website I would be surprised I cannot do the same with the app.

Thank you very much in advance, Jules

like image 254
Jules Marcilhacy Avatar asked Sep 03 '13 21:09

Jules Marcilhacy


1 Answers

You can use UIActivityViewController.
You first have to create a list of the things you want to share: an URL, a string, etc like this

NSArray *activityItems = @[[NSURL URLWithString:@"www.link-to-share.com], @"What you want written above"];

Afterwards, you just have to create the UIActivityViewController with the things you want to share and present it modally:

UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];

You can also add a completion block so that you are notified when the user is done with the sharing:

[activityController setCompletionHandler:^(NSString *activityType, BOOL completed){
    //do stuff
}];
like image 83
user3232710 Avatar answered Oct 18 '22 08:10

user3232710