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];
}
}
If you delete the Facebook app on the device, the initial text will appear.
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];
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With