简体   繁体   中英

FBDialogs canPresentMessageDialogWithParams returns false

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];

}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM