5

I'm currently trying to add Facebook SDK to the iOS version of my app. The login, logout, share, and request features are all currently working, but I'm having difficulty getting the MessageDialog feature to work. The Facebook app and the Facebook Messenger app are currently installed on my devices. However, every time I call 'FBDialog canPresentMessageDialogWithParams:params' it returns false.

My guess is that this feature doesn't work while the app is still in development mode, but that is just a guess. Does anyone know if Message Dialog works with apps that are under development? Or do you have any ideas as to what I am doing wrong?

I've also included my code in case I've made any bone-headed mistakes. Any help is greatly appreciated!

// Check if the Facebook app is installed and we can present the share dialog
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:@"https://www.facebook.com/"];
params.name = @"Flash Bear";
params.caption = nil;
params.picture = nil;
params.linkDescription = @"I'm playing Flash Bear. Why don't you come join me?";


// If the Facebook Messenger app is installed and we can present the share dialog
if ([FBDialogs canPresentMessageDialogWithParams:params]) {
    // Present message dialog


    [FBDialogs presentMessageDialogWithParams:params
                                  clientState:nil
                                      handler: ^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                        if(error) {
                                            // An error occurred, we need to handle the error
                                            // See: https://developers.facebook.com/docs/ios/errors
                                            NSLog(@"Error messaging link: %@", error.description);
                                        } else {
                                            // Success
                                            NSLog(@"result %@", results);
                                        }
                                    }];
} else {
    // Present the feed dialog
    // Put together the dialog parameters

    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Sorry!"
                                                      message:@"There was an error connecting to FB Messenger. Please make sure that it is installed."
                                                     delegate:nil
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
    [message show];

}
Christoferson
  • 171
  • 1
  • 7
  • 1
    Just an update, in case anyone else is having this problem, it doesn't seem to be a development issue. I recently launched my app and the message dialog still doesn't work on iOS. I did manage to get it to work on Android though. I've decided to remove this feature from my iOS version, but if anyone has any ideas as to what went wrong I'd be happy to hear it. – Christoferson Oct 05 '14 at 04:52

1 Answers1

0

I also had same problem with my application.

I resolved it by checking active session state. If state for active session is other than open then we need to open session again.

For doing the same use following code.

if([FBSession activeSession].state != FBSessionStateOpen){

   BOOL result = [FBSession openActiveSessionWithAllowLoginUI:NO];
   if(result)
   {
      //Do your stuff here
   }
}

Best luck.

Nirmal Choudhari
  • 559
  • 5
  • 17