raptor
raptor

Reputation: 291

How to check if Facebook is loggedIN in device ? objective C

I am implementing the Facebook SDK into my app . I am using FBLoginView to login with Facebook. I have a UIButton, which I'm using to share on a user's Facebook wall. Now I don't want to login using FBLoginView , i want to check if there is a Facebook app, and if the user has logged in.

- (IBAction)pickFriendsList:(UIButton *)sender
{
    FBFriendPickerViewController *friendPickerController = [[FBFriendPickerViewController alloc] init];
    friendPickerController.title = @"Pick Friends";
    [friendPickerController loadData];

    // Use the modal wrapper method to display the picker.
    [friendPickerController presentModallyFromViewController:self animated:YES handler:
     ^(FBViewController *sender, BOOL donePressed) {

         if (!donePressed) {
             return;
         }
         NSString* fid;
         NSString* fbUserName;

         for (id<FBGraphUser> user in friendPickerController.selection)
         {
             NSLog(@"\nuser=%@\n", user);
             fid = user.id;

             fbUserName = user.name;

             NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"test", @"message", @"http://webecoist.momtastic.com/wp-content/uploads/2009/01/nature-wonders.jpg", @"picture", @"Sample App", @"name",fid,@"tags",fid,@"to",@"106377336067638",@"place", nil];


                 [FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/feed",fid] parameters:params               HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection,id result,NSError *error)
                                          {

             [FBWebDialogs presentFeedDialogModallyWithSession:nil                                                     parameters:params  handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)

              {
                  if (error)
                  {
                      // Error launching the dialog or publishing a story.

                      NSLog(@"Error publishing story.");
                  }
                  else
                  {
                      if (result == FBWebDialogResultDialogNotCompleted) {
                          // User clicked the "x" icon
                          NSLog(@"User canceled story publishing.");
                      }
                      else
                      {

                          // Handle the publish feed callback

                               //Tell the user that it worked.

                           }


                  }
              }];
                                              }];

         }

     }];

}

Upvotes: 0

Views: 1707

Answers (2)

Ravi Trivedi
Ravi Trivedi

Reputation: 2360

I am assuming that you are using iOS 6 sdk. In which case, Use below code (workable for device) :

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) 
{

//user is already logged in using iOS integrated FB a/c

}
else
{

//user is not logged in

}

Note: FBSession can't check this criteria. So session check with FBSession has a different meaning from above code.

Regards,

Upvotes: 3

Peteee24
Peteee24

Reputation: 530

Check for the URL Scheme fb://

[[UIApplication sharedApplication] canOpenURL:@"fb://"] returns YES if Facebook App is installed. This post lists, de available URL schemes for Facebook: https://stackoverflow.com/a/5707825/1511668

Maybe fb://online is what you are looking for.

Upvotes: 0

Related Questions