0

我正在将 Facebook SDK 实施到我的应用程序中。我正在使用 FBLoginView 登录 Facebook。我有一个UIButton,我用来在用户的 Facebook 墙上分享。现在我不想使用 FBLoginView 登录,我想检查是否有 Facebook 应用程序,以及用户是否已登录。

- (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.

                           }


                  }
              }];
                                              }];

         }

     }];

}
4

2 回答 2

3

我假设您使用的是 iOS 6 sdk。在这种情况下,请使用以下代码(适用于设备)

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) 
{

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

}
else
{

//user is not logged in

}

注意:FBSession 不能检查这个条件。所以使用 FBSession 进行会话检查与上面的代码有不同的含义。

问候,

于 2013-04-17T02:32:59.720 回答
0

检查 URL 方案 fb://

[[UIApplication sharedApplication] canOpenURL:@"fb://"]如果安装了 Facebook 应用程序,则返回 YES。这篇文章列出了 Facebook 的可用 URL 方案:https ://stackoverflow.com/a/5707825/1511668

也许 fb://online 是您正在寻找的。

于 2013-04-16T18:48:40.337 回答