Graham French
Graham French

Reputation: 201

setInitialText method in SLComposeViewController iOS 8.3 does not show text in Facebook sheet

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];
    }
}        

Upvotes: 20

Views: 5300

Answers (2)

Asif Asif
Asif Asif

Reputation: 1511

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];
}];

Upvotes: 1

Chrisswong
Chrisswong

Reputation: 158

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

Upvotes: 15

Related Questions