Chr*_*son 5 facebook ios messagedialog facebook-messenger
我目前正在尝试将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];
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序也遇到了同样的问题。
我通过检查活动会话状态解决了这个问题。如果活动会话的状态不是打开,那么我们需要再次打开会话。
要执行相同的操作,请使用以下代码。
if([FBSession activeSession].state != FBSessionStateOpen){
BOOL result = [FBSession openActiveSessionWithAllowLoginUI:NO];
if(result)
{
//Do your stuff here
}
}
Run Code Online (Sandbox Code Playgroud)
好运。
| 归档时间: |
|
| 查看次数: |
665 次 |
| 最近记录: |