简体   繁体   English

将Facebook / Twitter共享添加到应用程序的简单方法?

[英]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. 我正在寻找将我的应用程序添加Facebook和Twitter共享按钮选项的解决方案。 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. 我已经用谷歌搜索了,发现了shareKit,但是它不是ARC,所以会抛出很多错误,这对我没有用。 Any other options? 还有其他选择吗? they need to be ARC compatible. 它们需要与ARC兼容。

I want a SDK that I can drop in, throw in the App ID's and be done. 我想要一个可以插入,放入应用程序ID并完成的SDK。

If you want simple sharing, the following can be used for Twitter and Facebook: 如果要简单共享,则可以将以下内容用于Twitter和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. 对于Facebook,只需将SLServiceTypeTwitter替换为SLServiceTypeFacebook。 The "Social" framework must be imported :-) 必须导入“社交”框架:-)

You can use UIActivityViewController : 您可以使用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 参考: https : //developer.apple.com/library/ios/documentation/uikit/reference/UIActivityViewController_Class/Reference/Reference.html

是的,请使用本机iOS共享对话框: UIActivityViewController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM