How to detect If user is Logged in the Facebook from native OS

960 Views Asked by At

Is there a way to check if the user is signed in in the device settings? If yes, how?

Also, is there a way to direct the user to the device settings directly to the Facebook account tab? If yes, how?

The thing is, I want to detect if the user is already logged in in the device settings. If yes, then I will let the user share. If not, I want to redirect the user to the device settings in the fb tab and let him decide if he wants to log in or not.

2

There are 2 best solutions below

0
Rupal Patel On BEST ANSWER
if([SLComposeViewController instanceMethodForSelector:@selector(isAvailableForServiceType)] != nil)
{
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {
        SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [composeViewController setInitialText:@"Hello"];
        [composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) {

            switch (result) {
                case SLComposeViewControllerResultCancelled:
                    [UIAlertView showAlertViewWithTitle:APPNAME message:@"Facebook sharing canceled!!"];
                    break;
                case SLComposeViewControllerResultDone:
                    [UIAlertView showAlertViewWithTitle:APPNAME message:@"Successfully posted on Facebook."];
                    break;

                default:
                    break;
            }
        }];
        [[self.window rootViewController] presentViewController:composeViewController animated:YES completion:nil];
    }
1
Suhail kalathil On
ACAccountType *facebookAccountType;
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSArray *facebookAccounts = [accountStore accountsWithAccountType:facebookAccountType];