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?

Answers


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


It seems that [SLComposeViewController isAvailableForServiceType:] returns true in the simulator, even if you haven't set up an account there.


I don't think you will get any system alert (I am not sure but based on Twitter experience). Although I have seen it in some recent blogs/web posts but it is not working for me too. I suggest in such case you should rather ask for user's FB credentials (custom dialog or FBDialog) and add FB account in iPad. The below code is not tested but you can get an idea. I am doing similar thing for Twitter & that is working fine in my apps.

ACAccountStore *store = [[ACAccountStore alloc] init] ;
    ACAccountType *fbType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    [store requestAccessToAccountsWithType:fbType options:[NSDictionary dictionaryWithObjectsAndKeys:kAppID,ACFacebookAppIdKey, nil] completion:^(BOOL granted, NSError *error) {
        if(YES) {
            ACAccount *fbAccount = [[ACAccount alloc] initWithAccountType:[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook]];

            ACAccountCredential *outhCredential = [[ACAccountCredential alloc] initWithOAuth2Token:[appDelegate.facebook accessToken] refreshToken:refesrhToken expiryDate:[appDelegate.facebook expirationDate]];


            fbAccount.credential = outhCredential;

            [store saveAccount:fbAccount withCompletionHandler:^(BOOL success, NSError *error) {
                if(success)
                {
                    [self performSelectorOnMainThread:@selector(showFBPostSheet) withObject:nil waitUntilDone:NO];
                }
            }];

            [outhCredential release];
            [fbAccount release];
            [store release];
        }
        // Handle any error state here as you wish
    }];

Need Your Help

ReSharper C# naming style for private methods and properties

c# coding-style resharper naming-conventions

I like to make the first letter of private methods, properties and events lowercase and the first letter of public methods, properties and events uppercase. However, in ReSharper 7.1 there is only ...

Get rid of padding/margin around <canvas> element?

html gwt canvas

I have a canvas object in a div. The canvas seems to have a padding around it somehow. I want its edges to touch the edges of the browser screen: