Simple way to add Facebook/Twitter share to app?

不打扰是莪最后的温柔 提交于 2020-01-02 10:18:31

问题


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.


回答1:


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 :-)




回答2:


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




回答3:


Yes use the native iOS sharing dialog: UIActivityViewController



来源:https://stackoverflow.com/questions/21557614/simple-way-to-add-facebook-twitter-share-to-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!