iOS:如何在社交网络上分享文字和图片?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29890747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS: How to share text and image on social networks?
提问by user3290180
Please, can you tell me if I'm doing mistakes?
拜托,如果我做错了,你能告诉我吗?
NSString *sharedMsg=[NSString stringWithFormat:@"Hello world"];
UIImage* sharedImg=[UIImage imageNamed:@"image"];
NSArray* sharedObjects=[NSArray arrayWithObjects:sharedMsg, sharedImg, nil];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc]
initWithActivityItems:sharedObjects applicationActivities:nil];
activityViewController.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityViewController animated:YES completion:nil];
At runtime when I select the icon of Facebook the text is missing, the image is correctly displayed.
My xcode is 6.3.1, tested on iPad.
在运行时,当我选择 Facebook 的图标时,文本丢失,图像正确显示。
我的 xcode 是 6.3.1,在 iPad 上测试过。
回答by Paulw11
It seems that a recent update to the Facebook application has replaced the in-built Facebook share activity with one that ignores status text - If you remove the Facebook app from your device the text will be displayed using the code you have. If you have the Facebook app installed you get images, URLs but not the text
最近对 Facebook 应用程序的更新似乎已将内置的 Facebook 共享活动替换为忽略状态文本的活动 - 如果您从设备中删除 Facebook 应用程序,文本将使用您拥有的代码显示。如果您安装了 Facebook 应用程序,您将获得图像、URL 而不是文本
Facebook's policies don't allow you to pre-populate status messages and require all content to be user generated - while I understand the intention behind this, I personally think it is kind of stupid in many cases - For example in my game I want to pre-populate the user's score, but now I can't, so the user is presented with an empty dialog box. I will probably simply remove the Facebook sharing option as no-one will ever use it now.
Facebook 的政策不允许您预先填充状态消息并要求用户生成所有内容 - 虽然我理解这背后的意图,但我个人认为在许多情况下这有点愚蠢 - 例如在我的游戏中我想预先填充用户的分数,但现在我不能,所以用户会看到一个空对话框。我可能会简单地删除 Facebook 共享选项,因为现在没有人会使用它。
This responsefrom Facebook confirms that the behaviour is by design
Facebook 的这一回应证实了这种行为是有意为之
回答by Khuong
Here is the answer in Swift. It may not help your problem, but it might be helpful with someone looking for this title. Just create a button and it's action. And install the button's action like this.
这是 Swift 中的答案。它可能无助于您的问题,但它可能对寻找此标题的人有所帮助。只需创建一个按钮,它的动作。并像这样安装按钮的动作。
Note: You have to log in your facebook or twitter by going to setting. Then do like this.
注意:您必须通过转到设置登录您的 facebook 或 twitter。然后这样做。
@IBAction func onShareTouched(sender: AnyObject) {
print("share")
let myShare = "My beautiful photo! <3 <3"
let image: UIImage = UIImage(named: "yourImageNameHere")
let shareVC: UIActivityViewController = UIActivityViewController(activityItems: [(image), myShare], applicationActivities: nil)
self.presentViewController(shareVC, animated: true, completion: nil)
}
回答by Arpit Lokwani
NSString* text=@"Hello world";
NSURL *myWebsite = [NSURL URLWithString:@"http://www.website.com/"];
// UIImage * myImage =[UIImage imageNamed:@"myImage.png"];
NSArray* sharedObjects=@[text,myWebsite];
UIActivityViewController * activityViewController=[[UIActivityViewController alloc]initWithActivityItems:sharedObjects applicationActivities:nil];
activityViewController.popoverPresentationController.sourceView = self.view;
[self presentViewController:activityViewController animated:YES completion:nil];