将ios中的应用邀请发送给Facebook好友时出错

我正在尝试向Facebook好友发送应用邀请,但收到以下错误

app invite error:Error Domain=com.facebook.sdk.core Code=9 "The operation couldn't be completed. (com.facebook.sdk.core error 9.)" 

下面是我的代码

 -(IBAction)buttonTapped:(id)sender { FBSDKAppInviteContent *content = [[FBSDKAppInviteContent alloc] init]; content.appLinkURL = [NSURL URLWithString:@"https://fb.me/115385318808986"]; [FBSDKAppInviteDialog showWithContent:content delegate:self]; } #pragma mark - FBSDKAppInviteDialogDelegate - (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results { // Intentionally no-op. } - (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error { NSLog(@"app invite error:%@", error); NSString *message = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?: @"There was a problem sending the invite, please try again later."; NSString *title = error.userInfo[FBSDKErrorLocalizedTitleKey] ?: @"Oops!"; [[[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; } 

当我试图打印error.userInfo时,它显示一个空白字典。 请指导。

对于facebook sdk 4.0及更高版本

首先创建一个applink。

 FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init]; content.appLinkURL = [NSURL URLWithString:@"https://www.google.com/myapplink"]; //optionally set previewImageURL content.appInvitePreviewImageURL = [NSURL URLWithString:@"https://www.google.com/my_invite_image.jpg"]; // present the dialog. Assumes self implements protocol `FBSDKAppInviteDialogDelegate` [FBSDKAppInviteDialog showWithContent:content delegate:self]; 

请参阅此链接https://developers.facebook.com/docs/app-invites/ios

编辑:

当您创建应用程序链接并且必须提供URL方案时,此url方案将添加到项目信息plist.after您在face book开发人员设置页面中添加face book canvas平台,并提供canvasURL并保存它。

如果你一直在寻找像我这样的地方找出它为什么不起作用,结果Facebook正在弃用App Invites并且将在2/6/2018完全停止工作:

https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/

我也有这个错误。 是什么修复它添加

[FBSDKAppEvents activateApp];

applicationDidBecomeActive:(UIApplication *)application

在appDelegate中。 另请参见https://developers.facebook.com/docs/app-events/ios#appActivation