2

When i try to post to facebook within my app I get the error: Please Log In You need to be logged into the Facebook app to share this photo.

I am logged into the Facebook app as well as being logged in through the settings.

I have tested posting on the simulator and it works fine. When I test on my device is when I get the problem.

I have read some other posts about this issue. It was supposedly reported to Facebook already.

I was just wondering if other peoples facebook posting was working and if I can do anything special to correct my problem.

if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]){

    //Present twiter message box
    SLComposeViewController *facebook = [[SLComposeViewController alloc] init];
    facebook = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    //set the initial text for tweet
    [facebook setInitialText:defaultPost];
    [facebook addURL:[NSURL URLWithString:@"http://bit.do/flappyghost"]];
    [facebook addImage:[UIImage imageNamed:@"appIcon.png"]];

    //present viewcontroller
    [self presentViewController:facebook animated:YES completion:nil];

} else {

    //handle the error if twitter is not available
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No Facebook Account is set up on this device!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];

    [alert show];

}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Andrew
  • 391
  • 3
  • 15

1 Answers1

0

I don't quite know the issue here but adding a completion handler got it working for me:

SLComposeViewController *facebook = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebook setInitialText:@"Lorem Ipsum"];
[facebook addURL:[NSURL URLWithString:@"http://stackoverflow.com"]];
[facebook setCompletionHandler:^(SLComposeViewControllerResult result) {
    switch (result) {
        case SLComposeViewControllerResultCancelled:
            NSLog(@"Post Canceled");
            break;
        case SLComposeViewControllerResultDone:
            NSLog(@"Post Sucessful");
            break;
        default:
            break;
    }
}];
[self presentViewController:facebook animated:YES completion:nil];
bangdel
  • 2,523
  • 5
  • 28
  • 42