Reputation: 323
The functionality of SLComposeViewController no longer works as expected with the newest Facebook iPhone app update as of April 24th. Any initial text specified is ignored, though the setInitialText method returns true as if it was successful. The dialog then always returns "Done" whether you hit "Done" or "Cancel". I realize this is an Apple call and I'm not even using the Facebook SDK, but I have verified that everything works perfectly with the previous version of the Facebook App installed but when you upgrade the Facebook app on your iPhone, this functionality no longer works as expected.
Note that the result of the completion handler now always returns "Done" - even when you hit "Cancel" and also, the setInitialText:
does nothing now. Verified that the same code worked pre-the april 24th release.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:@"hiiiiiii"];
[controller setCompletionHandler:^(SLComposeViewControllerResult result)
{
if (result == SLComposeViewControllerResultCancelled)
{
NSLog(@"The user cancelled.");
}
else if (result == SLComposeViewControllerResultDone)
{
NSLog(@"The user posted to Facebook");
}
}];
[self presentViewController:controller animated:YES completion:nil];
}
else
{
SCLAlertView *alert = [[SCLAlertView alloc] init];
[alert showWarning:self title:@"alert" subTitle:@"facebook not installed" closeButtonTitle:@"ok" duration:0.0f];
}
Upvotes: 6
Views: 2476
Reputation: 606
At the time of this post, FB's still not allowing to set initial text, even using FB SDK.
A way I implemented to bypass the issue is to copy the content to clipboard and show a dialog to notify users that they can paste the preset content.
Upvotes: 0
Reputation: 453
setInitialText:
is not working anymore because Facebook has recently changed its policy about prefilling, but addURL:
is still working and may be useful.
SLComposeViewController *mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
NSURL *url = [[NSURL alloc] initWithString:linkString];
[mySLComposerSheet addURL:url];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(@"SLComposeViewControllerResultCancelled");
break;
case SLComposeViewControllerResultDone:
NSLog(@"SLComposeViewControllerResultDone");
break;
}
}];
This way I can prefill Facebook post composer with the URL to my App.
I hope it to be useful.
Upvotes: -2