作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我目前正在尝试将 Facebook SDK 添加到我的应用程序的 iOS 版本中。登录、注销、共享和请求功能目前都在工作,但我很难让 MessageDialog 功能工作。我的设备上目前安装了 Facebook 应用程序和 Facebook Messenger 应用程序。但是,每次我调用“FBDialog canPresentMessageDialogWithParams:params”时,它都会返回 false。
我的猜测是当应用程序仍处于开发模式时此功能不起作用,但这只是一个猜测。有谁知道消息对话框是否适用于正在开发的应用程序?或者您对我做错了什么有任何想法?
我还包含了我的代码,以防我犯任何愚蠢的错误。非常感谢任何帮助!
// 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];
}
最佳答案
我的申请也遇到了同样的问题。
我通过检查事件 session 状态解决了这个问题。如果事件 session 的状态不是打开,那么我们需要再次打开 session 。
要执行相同的操作,请使用以下代码。
if([FBSession activeSession].state != FBSessionStateOpen){
BOOL result = [FBSession openActiveSessionWithAllowLoginUI:NO];
if(result)
{
//Do your stuff here
}
}
祝你好运。
关于ios - FBDialogs canPresentMessageDialogWithParams 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25355164/
我目前正在尝试将 Facebook SDK 添加到我的应用程序的 iOS 版本中。登录、注销、共享和请求功能目前都在工作,但我很难让 MessageDialog 功能工作。我的设备上目前安装了 Fac
我是一名优秀的程序员,十分优秀!