Search code examples
iosobjective-cfacebookfacebook-ios-sdk

Post plain text on facebook wall from iOS application


Yet, it's rather popular question and fb's doc are very clear, I stuck with the following situation: I want user to post from my iOS app to his facebook wall an article,that he wants to share with friends(but this article on the website is available only for subscribed users, so I can't post a link to the article I need to post all full article's text at once)

    NSMutableDictionary *params =
    [NSMutableDictionary dictionaryWithObjectsAndKeys:
     _title, @"name",
     _htmlBody, @"description",
      nil];
    [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                           parameters:params
                                              handler:handler];

As you can see, parameter "link" is missed in params, and this causes, that post on the wall is empty!Is there a workaround how to post on the wall plain text without link, photo, etc.?

Note: when I add any working link in params, I can see post on the wall, but, anyway description is cut, so just several lines from the article is seen.(I think its because param "description" allows to have a particular size, m.b 1000 characters)

Many thanks in advance.


Solution

  • Using SLComposeViewController available in iOS 6.0 and above

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
            SLComposeViewController *facebookShare = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
            NSString *shareText = @"This is my share post!";
            [facebookShare setInitialText:shareText];
    
            [facebookShare setCompletionHandler:^(SLComposeViewControllerResult result) {
    
                switch (result) {
                    case SLComposeViewControllerResultCancelled:
                        NSLog(@"Post Canceled");
                        break;
                    case SLComposeViewControllerResultDone:
                        NSLog(@"Post Sucessful");
                        break;
                    default:
                        break;
                }
            }];
    
            [self presentViewController:facebookShare animated:YES completion:nil];
        }