20

The code snippet below is the callback for an on screen button. The Facebook sheet appears but contains no text. However, if you replace SLServiceTypeFacebook with SLServiceTypeTwitter it does show the initial text. I am using XCode 6.3.1 and iOS 8.3 on an iPhone 6. Thank you in advance.

-(IBAction)facebookButton:(id)sender
{
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {
        NSString* facebookText = @"Awesome App";
        SLComposeViewController *fbPostSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
        [fbPostSheet setInitialText:facebookText];
        [self presentViewController:fbPostSheet animated:YES completion:nil];
    }
    else{
         UIAlertView *alertView = [[UIAlertView alloc]
                              initWithTitle:@"Unable to Connect to Facebook"
                              message:@"Make sure your device has an internet connection and you have your Facebook account setup in the Settings App"
                              delegate:self
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
        [alertView show];
    }
}        
Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Graham French
  • 201
  • 2
  • 3

2 Answers2

15

If you delete the Facebook app on the device, the initial text will appear.

squarefrog
  • 4,750
  • 4
  • 35
  • 64
Chrisswong
  • 158
  • 4
  • 13
    Deleting the Facebook app on my iPhone does allow the inititial text to appear. However, I cannot ask my users to delete their facebook app so they can post their score on Facebook. – Graham French May 02 '15 at 12:40
  • You may want to have a custom UI for your case. Please remind that you have to submit your app for Facebook review. I had also googled this issue but sadly i did not find any documentations about this.. – Chrisswong May 04 '15 at 10:30
  • I'm having the same issue in my game. But, to be clear, @Chrisswong, are you saying that we have to register our apps with Facebook to fix this issue? – Steven W. Disbrow May 04 '15 at 19:14
  • 1
    Making your own UI for Facebook sharing allows you provide any initial texts for Facebook sharing. However, you must register on [Facebook developer site](http://developer.faceobok.com) , enable "publish_actions" permission and submit iOS simulator build for Facebook review so that you can go live with Facebook sharing and share to public. You must be aware of this [POLICY](https://developers.facebook.com/docs/apps/review/prefill) for the initial text you provided. – Chrisswong May 05 '15 at 09:03
  • @Chrisswong as I understand from Policy link you provided, Facebook now reject using of "prefill". So making your own compose controller will not solve the problem. I guess that this is a reason of change in iOS 8.3. – John Tracid May 09 '15 at 16:48
  • @JohnTracid In fact one of my app is using custom UI for Facebook sharing. However, i pre-filled the text inside a textview so that user can edit the text and finally Facebook review approved this. From i understand the "pre-fill" is something that the user is not able to edit and it shows in the shared content. – Chrisswong May 11 '15 at 09:40
  • Use Facebook share dialog – Kirit Vaghela Jun 20 '15 at 09:48
  • 1
    @Chrisswong can you share the link of your application so that we get an idea of creating custom dialog. I am sucked with the same since few weeks. Thanks – Usman Nisar Jul 07 '15 at 05:15
  • @ManiKhalil no worries! it was pretty long ago so most of us aware this issues and provide other alternatives to the users. – Chrisswong Feb 25 '16 at 14:01
1

It actually works if you set the text inside the completion handler:

NSString* facebookText = @"Awesome App";
SLComposeViewController *fbPostSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
//[fbPostSheet setInitialText:facebookText];
[self presentViewController:fbPostSheet animated:YES completion:^
{
    [fbPostSheet setInitialText:facebookText];
}];
Asif Asif
  • 1,511
  • 14
  • 24