0

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.

                           }


                  }
              }];
                                              }];

         }

     }];

}
jakenberg
  • 2,125
  • 20
  • 38
raptor
  • 291
  • 1
  • 9
  • 17

2 Answers2

3

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,

Ravi Trivedi
  • 2,340
  • 2
  • 14
  • 20
  • how to get SLComposeViewController ? should i do it in viewDidLoad and how to check whether the user has logged in or not and just using this condition should do it ? – raptor Apr 17 '13 at 02:42
  • 1
    Add "Social.framework" in your project if not added and then import "Social/Social.h". Then you use the SLComposeViewController class. You can use this check whenever you want to post, tag .... etc. cheers ! – Ravi Trivedi Apr 17 '13 at 02:50
  • i am sharing details to friends post from my fb profile .when the user is logged IN. i will be executing the above method which shares post to friends wall .So can i use SLComposeViewController in the above method ? The above method is my sharebutton – raptor Apr 17 '13 at 03:34
  • This is for the person who is logged in. In this case, you. Because you are connecting to FB using your configured credentials. Regards, – Ravi Trivedi Apr 17 '13 at 03:47
  • This is not pertinent to checking whether or not the user is logged in w/ Facebook – jakenberg Apr 17 '13 at 04:30
  • what do you mean ? This is to check whether user has account setup for particular service ie: FB, Twitter... in the device and whether his a/c service is available. If a/c service is available then he does not need to log in again. – Ravi Trivedi Apr 17 '13 at 04:38
  • Okay, so why go through all of this trouble (not to mention messing with user data when you shouldn't be) just to determine something as menial as an active session. Both Facebook & Twitter happily support sessions. Any legitimate SDK used for accounts has to! – jakenberg Apr 17 '13 at 04:50
  • Because this code checks whether user is logged in using iOS integrated FB a/c. FBSession can't check this. Read his Question. I think you should up vote. – Ravi Trivedi Apr 17 '13 at 05:00
  • @Ravi i am adding this in a method and i am calling this in the above method..i am not able to select friend and post prerequisite text to friends wall – raptor Apr 17 '13 at 06:14
  • @Ravi i am having problem in cancelling notification can u help me out http://stackoverflow.com/questions/16477894/uilocalnotification-firing-even-after-notification-is-cancelled/16478686?noredirect=1#comment23647803_16478686 In my program the notification is fired for 3 times a day (Morning , afternoon , evening) when i cancel a notification say after morning the notification is not fired for rest of the day (this is the way i want it to perform) ...but the notification is getting fired the next day (morning) .. – raptor May 11 '13 at 04:27
  • @raptor, I will definitely once I get some free time. – Ravi Trivedi May 12 '13 at 10:30
0

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.

Community
  • 1
  • 1
Peteee24
  • 510
  • 4
  • 8