我目前正在尝试将 Facebook SDK 添加到我的应用程序的 iOS 版本中。登录、注销、共享和请求功能目前都在工作,但我很难让 MessageDialog 功能工作。Facebook 应用程序和 Facebook Messenger 应用程序目前已安装在我的设备上。但是,每次我调用 'FBDialog canPresentMessageDialogWithParams:params' 时它都会返回 false。
我的猜测是,当应用程序仍处于开发模式时,此功能不起作用,但这只是一个猜测。有谁知道 Message Dialog 是否适用于正在开发的应用程序?或者你对我做错了什么有任何想法?
我还包括了我的代码,以防我犯了任何愚蠢的错误。任何帮助是极大的赞赏!
// 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];
}