1
votes

I have to follow below requirement to do Facebook share:

  1. If user is logged in Facebook app, just ask them to do share with dialog popup.
  2. If user is not logged-in to Facebook app, ask them to do login first and then show the share dialogue.

I'm using below code to show share dialogue.

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:permalink];
content.contentDescription = [NSString stringWithFormat:@"%@",smallDescription];
content.imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@",guid]];

[FBSDKShareDialog showFromViewController:self
                             withContent:content
                                delegate:nil];

Above code works when user is logged in but if not logged in it's shows alert message "You need to be logged into the Facebook app to share this link".

1
But do you have in app facebook login? Or you want the user to login in the browser/facebook_app? In the latter case then the user will be likely prompted automatically eventually. In the first case it is way more complicated i guess. - jalone
I guess this is handled automatically by SLComposeViewController, you don't need to do anything - P.J
@jalone I do have in app facebook login but there is two way user can do login, Facebook and email. If user do email login and they are trying to do Facebook share. Problem is if user do logout from Facebook application and when they do share on my application i don't want them to see the alert messaging saying that please do login instead of ask them to do login and show share dialogue. - Jay
@P.J I tried with SLComposeViewController also, It was showing an alert message "You need to be logged into the Facebook app to share the this link" Instead of i want to ask user to do login and show share. - Jay

1 Answers

1
votes
 NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                      @"ProjectName", @"name",
                                      @"Title", @"caption",
                                      @"Description", @"description",
                                      @"Link", @"link",
                                      @"ImageUrl", @"picture",
                                      nil];
// Show the feed dialog
 [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                               parameters:param

  handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {                                                  
  if (error) {
   // An error occurred, we need to handle the error
   // See: https://developers.facebook.com/docs/ios/errors
  NSLog(@"Error publishing story: %@", error.description);
   } 
  else {
  if (result == FBWebDialogResultDialogNotCompleted) {
   // User canceled                                            
    NSLog(@"User cancelled.");
  } else {
  // Handle the publish feed callback
  NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

  if (![urlParams valueForKey:@"post_id"]) {
  // User canceled.
   NSLog(@"User cancelled.");
  } else {
  // User clicked the Share button
  NSString *result = [NSString stringWithFormat: @"Posted story, id:          %@", [urlParams valueForKey:@"post_id"]];
  NSLog(@"result %@", result);
  UIAlertView *successAlert = [[UIAlertView alloc]initWithTitle:@"" message:@"Posted Successfully!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  [successAlert show];
                                                                               }}}}];