46

I am trying to share a text on Facebook with SLServiceTypeFacebook on IOS 8.3. But the popup text box displayed empty. I want it to be displayed with text in it. Below you can see the code I use for that.

 if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) 
 {
       SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

       [controller setInitialText:@"First post from my iPhone app"];
       [self presentViewController:controller animated:YES completion:Nil];
  }
stevekohls
  • 2,214
  • 23
  • 29
birdcage
  • 2,638
  • 4
  • 35
  • 58
  • Does `setInitialText` return `YES` or `NO`? – jszumski Apr 28 '15 at 17:19
  • 5
    This is a known issue on iOS 8.3: "Greg Pierce (@agiletortoise) 4/27/15, 11:22 AM UIKit folks: New iOS 8.3 problem with [SLComposeViewController setInitialText]. rdar://20709403 openradar.appspot.com/radar?id=50611… – Dean Apr 28 '15 at 17:22
  • @deanware can you please send the link for that? Do you suggest me to wait new iOS version? – birdcage Apr 28 '15 at 17:40
  • 2
    OpenRadar: http://openradar.appspot.com/radar?id=5061141176778752 – jszumski Apr 28 '15 at 17:41
  • possible duplicate of [SLComposeViewController setInitialText not showing up in View](http://stackoverflow.com/questions/29970741/slcomposeviewcontroller-setinitialtext-not-showing-up-in-view) – MrCranky Jun 03 '15 at 11:47
  • As others have already mentioned, Facebook does not allow for prefilling anymore, rendering "setInitialText" of a SLComposeViewController for the SLServiceTypeFacebook useless. What was very useful for me, however, is to realize that adding an url or an image is still perfectly possible and in line with the Facebook terms of service. If you have the resources to do it, e.g. a webserver to host the post on - just add a link to the webpage you want the user to see. Facebook will prefetch the summary of this page and display it embedded anyway. Better than trying to comment on the user's behalf. – Integrating Stuff Sep 14 '15 at 18:29

3 Answers3

32

It seems to be a problem having installed the latest Facebook app update (v29). Removing it "fixes" the problem.

https://developers.facebook.com/bugs/1632385646995079/ https://developers.facebook.com/bugs/962985360399542/

Update (Jun. 3, 2015)

Well. It seems that the new Facebook policy says that prefilling a message through setInitialText: is a prefill violation.

https://developers.facebook.com/docs/apps/review/prefill

So I guess the only way to share content from now on is the FBSDKShareDialog

https://developers.facebook.com/docs/sharing/ios

Yi Jiang
  • 3,938
  • 6
  • 30
  • 62
nnarayann
  • 1,449
  • 19
  • 24
  • 1
    It does seem strange that installing a 3rd party app (Facebook) can break a native SLComposeViewController. But I can confirm this is actually happening, even with the latest app update (v30). – hotdogsoup.nl May 27 '15 at 12:00
  • Same problem is generated in Facebook v31 as well. Please give me some suggestion in this. – Siddharth May 28 '15 at 07:01
  • 1
    I don't think apple is going to deprecate that SLComposeViewController. Some proper solution for this is still in wait. I don't personally want to implement FBSDKShareDialog as it will incur lots of hours, like, configuration, initialization of code, integration of SDK, etc. SLCompose...Controller only requires 4-5 lines of code. – Paresh Thakor Jul 06 '15 at 09:43
  • 1
    It is correct that Apple with new iOS 9 has new Facebook sdk in which setInitialText is deprecated. Same thing is with Instagram. You cannot add pre-defined comments in both of these apps programatically. – Dharmesh Siddhpura Sep 21 '15 at 08:18
  • Deprecated, in iOS9? Where do you see that? In the current docs, it does not say deprecated. While it still doesn't work. I'm with @Mobihunterz here - this is just a real pain in the ants. – Jonny Oct 06 '15 at 02:44
  • 2
    setInitialText is NOT deprecated for iOS 9 because it still works for Twitter and other Social framework services. As for a "Apple . . . has new Facebook sdk . . .", that is not true either. They are still using the Social framework. And this "sudden" change of heart from Facebook inconveniences me too. :/ EDIT: Personal experience with Facebook's own SDK has not been fun... and I don't recommend it if you ONLY need sharing support. – Erik Bean Oct 16 '15 at 03:48
  • @ErikBean I think it should be possible to make your own custom view based on ```SLComposeViewController``` which uses the ```Social``` framework, thus allowing you to pre-fill text. The only problem I can see with that, is that it requires an API key from Facebook and they will reject the API key when they see you app can pre-fill text :( – Supertecnoboff May 04 '16 at 14:50
  • No, Facebook automatically considers it a violation of it's T&C and ALL Dev Ops with FB are terminated. Your FB page can also be terminated as well if you used it in testing since you used your page to violate the T&C. Apple also will reject your app for violating section 8.5 of the App Store Review procedure. – Erik Bean Jun 09 '16 at 03:00
1

Gotta love the efficiencies of Facebook. Am a bit late on this but may help someone out.

#import <FBSDKShareKit/FBSDKShareKit.h>

FBSDKShareLinkContent  *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = self.urlForSocialMedia;
content.contentDescription = self.textForFB;
content.contentTitle = @"Results.";

[FBSDKShareDialog showFromViewController:self
                             withContent:content
                                delegate:self];
John Erck
  • 9,478
  • 8
  • 61
  • 71
PhillipOReilly
  • 609
  • 12
  • 28
  • Why you create a dialog and afterwards don't use it?!? In the end you are using the FBSDKShareDialog showFromViewController to create and show the dialog. – Freddy Oct 12 '15 at 17:02
  • I would imagine that the FBSDKShareDialog should just be dialog at the end. – Jake T. Nov 11 '15 at 23:32
  • 1
    The three dots at the beginning of this post will get me almost the same amount of time I spent to create the app itself! – Farhad Malekpour Dec 31 '15 at 10:47
0

Before setInitialText add # before this test. Code below. It is working for me

SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    [mySLComposerSheet setInitialText:@"#myInitialTextIsHere"];
    [mySLComposerSheet addURL:[NSURL URLWithString:strURL]];

    [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

        switch (result) {
            case SLComposeViewControllerResultCancelled:
                NSLog(@"Post Canceled");
                break;
            case SLComposeViewControllerResultDone:
                NSLog(@"Post Sucessful");
                break;

            default:
                break;
        }
    }];

    [self presentViewController:mySLComposerSheet animated:YES completion:nil];
Philip John
  • 5,275
  • 10
  • 43
  • 68