Phil
Phil

Reputation: 3045

Simple way to add Facebook/Twitter share to app?

I'm looking for a drop in solution to add a Facebook and Twitter share button option to my app. I've googled this of course, and found shareKit but it's non-ARC so just throws lots of errors, which is of no use to me. Any other options? they need to be ARC compatible.

I want a SDK that I can drop in, throw in the App ID's and be done.

Upvotes: 2

Views: 1004

Answers (3)

laurentcabon
laurentcabon

Reputation: 21

You can use UIActivityViewController:

NSArray * activityItems = activityItems = @[@"title", [NSURL URLWithString:@"urlstring"]];
    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    [self presentViewController:activityController animated:YES completion:nil];

References : https://developer.apple.com/library/ios/documentation/uikit/reference/UIActivityViewController_Class/Reference/Reference.html

Upvotes: 1

Jorn
Jorn

Reputation: 1044

If you want simple sharing, the following can be used for Twitter and Facebook:

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
    SLComposeViewController *slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    [slComposeViewController setInitialText:@"Your text"];
    [slComposeViewController addImage:[UIImage imageNamed:@"NameOfImage"]];
    [self presentViewController:slComposeViewController animated:YES completion:nil];
} else {
    //Show alert or in some way handle the fact that the device does not support this feature
}

For Facebook, simply replace SLServiceTypeTwitter with SLServiceTypeFacebook. The "Social" framework must be imported :-)

Upvotes: 3

rckoenes
rckoenes

Reputation: 69489

Yes use the native iOS sharing dialog: UIActivityViewController

Upvotes: 0

Related Questions