Search code examples
objective-ciosfacebookcocoa-touchios6

iOS6 Facebook: What to do if user has not configured Facebook?


I am using the new Facebook integration in iOS6 like the following:

SLComposeViewController *fbController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
    SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){

        [fbController dismissViewControllerAnimated:YES completion:nil];

        switch(result){
            case SLComposeViewControllerResultCancelled:
            default:
            {
                NSLog(@"Cancelled.....");

            }
                break;
            case SLComposeViewControllerResultDone:
            {
                NSLog(@"Posted....");
            }
                break;
        }};

    //[fbController addImage:[UIImage imageNamed:@"1.jpg"]];
    [fbController setInitialText:@"Test message"];
    [fbController addURL:[NSURL URLWithString:self.asset.url]];
    [fbController setCompletionHandler:completionHandler];
    [self presentViewController:fbController animated:YES completion:nil];
} else {
    NSLog(@"no facebook setup");
}

The problem here is, I am testing it without being logged into Facebook and all I get is the log message.

** Strange thing is, I get the dialog in the Simulator, but NOT the device!**

How can I show the the user an alert that tells them that they need to log in to Facebook? I have seen screenshots of a system alert, but I am not getting that for some reason. What have I done wrong?


Solution

  • Removing the check for [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook] fixed the issue for me.