找到你要的答案

Q:iOS: How to share text and image on social networks?

Q:iOS:如何在社交网络上分享文字和图片吗?

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.

请你告诉我,如果我在犯错误?

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.

answer1: 回答1:

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'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.

This response from Facebook confirms that the behaviour is by design

看来,最近更新到脸谱网应用程序已经取代了内置脸谱网共享活动与一个忽略状态文本-如果你删除脸谱网应用程序从您的设备文本将显示使用您的代码。如果你有脸谱网应用程序安装你得到的图像,网址,但不是文本

脸谱网的政策不允许你预先填充状态消息,并要求所有的内容是用户生成的-虽然我理解这背后的意图,我个人认为这是愚蠢的-在许多情况下,例如在我的游戏我想预先填充用户的评分,但现在我不能,所以用户可以在一个空的对话框。我可能会简单地删除脸谱网共享选项,因为没有人会使用它现在。

脸谱网的这一反应证实了行为是由设计

answer2: 回答2:

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.

Note: You have to log in your facebook or twitter by going to setting. Then do like this.

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

  }

这是斯威夫特的答案。它可能不会帮助你的问题,但它可能是有帮助的人寻找这个称号。只要创建一个按钮,它的行动。并安装按钮的动作像这样。

注意:您必须登录到您的脸谱网或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)

  }
answer3: 回答3:
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];
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];
ios  facebook  share  uiactivityviewcontroller