48

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.

user3290180
  • 4,260
  • 9
  • 42
  • 77

3 Answers3

95

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

Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • 12
    you are right, a senseless choice... the user could simply edit and change it before sending to his profile. This way Facebook will lose many shares. – user3290180 Apr 27 '15 at 09:06
  • Thanks for pointing this out, it was driving me bonkers! What a silly move by Facebook. – Ash May 19 '16 at 08:21
  • Only #hashtag is working for me. Plain text and URL's don't work anymore? – SDW Jul 21 '16 at 12:09
  • 1
    I'm not being able to share images, only URLs – User Sep 15 '16 at 13:40
  • Hey @Ixx, we also ran into the same problem. If you provide a link, the image will be ignore. Remove the link when sharing to Facebook & What's app will work. – Yuchen May 15 '17 at 14:18
8

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 khuong291
  • 11,328
  • 15
  • 80
  • 116
0
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];
  • Would you be able to add some context to this answer? Where do `GooglePlus` and `FacebookShare` objects come from? Have you tested this code with the latest Facebook app installed? – Paulw11 Apr 27 '15 at 10:46
  • Yes i tested, GooglePlus and FacebookShare are the Custom Subclass of UIActivity – Arpit Lokwani Apr 27 '15 at 11:38
  • You still haven't shown the code for `FacebookShare` - Presumably this is some implementation of sharing using the Facebook SDK. Use of the Facebook SDK requires agreement with Facebook terms which prohibit the pre-population of the text. – Paulw11 Apr 27 '15 at 12:32
  • Sorry @paulw actually i thought that u had used Custom UIActivity Subclass but actually not used . In your code you have so simply pass NSURL argument along with text for sharing in Social networks , i edited the code please try with new one .. Thanks !! – Arpit Lokwani Apr 28 '15 at 06:55
  • 1
    This won't work if you have the newest Facebook app installed - the text area is simply blank. It works if you have an older app or no app – Paulw11 Apr 28 '15 at 06:56
  • I had installed Facebook latest only yesterday i downloaded to rectify this error . I already ran your code with and without NSURL and checked in iPhone 6 it's working fine with NSURL . – Arpit Lokwani Apr 28 '15 at 07:08
  • 1
    The URL will be there but not the text. The text will be in a message or mail or Twitter – Paulw11 Apr 28 '15 at 07:09