如何从ios应用程序向facebook好友发送应用程序邀请



我有完整的发送邀请的代码,当我点击按钮时,会出现一个弹出菜单,在弹出菜单中说。。。

错误。

游戏请求可用于游戏。

我的代码邀请朋友在这里:

 NSDictionary *parameters = @{@"to":@""};
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
                                              message:@"message aaya kya"                                                    title:@"app request"
                                           parameters:parameters
                                              handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
 {
     if(error)
     {
         NSLog(@"Some errorr: %@", [error description]);
         UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Invitiation Sending Failed" message:@"Unable to send inviation at this Moment, please make sure your are connected with internet" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
         [alrt show];
        // [alrt release];
     }
     else
     {
         if (![resultURL query])
         {
             return;
         }
         
         NSDictionary *params = [self parseURLParams:[resultURL query]];
         NSMutableArray *recipientIDs = [[NSMutableArray alloc] init];
         for (NSString *paramKey in params)
         {
             if ([paramKey hasPrefix:@"to["])
             {
                 [recipientIDs addObject:[params objectForKey:paramKey]];
             }
         }
         if ([params objectForKey:@"request"])
         {
             NSLog(@"Request ID: %@", [params objectForKey:@"request"]);
         }
         if ([recipientIDs count] > 0)
         {
             //[self showMessage:@"Sent request successfully."];
             //NSLog(@"Recipient ID(s): %@", recipientIDs);
             UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Invitation(s) sent successfuly!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
             [alrt show];
             //[alrt release];
         }
         
     }
 }
                                          friendCache:nil];

}

那么我错在哪里了?请帮帮我。谢谢

好的,我理解如果你想向你的朋友发送应用程序请求,你应该使用FBSDKAppInviteContent。

这是代码:

FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:@"Your_App_Id"];
content.previewImageURL = [NSURL URLWithString:@"Your_app_previewimage"];
[FBSDKAppInviteDialog showWithContent:content
                             delegate:self];

这里是Your_App_Id,请参阅此链接。

它的委托方法:

- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results{
if (results) {
   }
}
- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error{
if (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];
   }
}

为什么不尝试FBSDKGameRequestContent(它需要Facebook SDK 4.0(?

注意:只有当你的应用类别是Facebook开发者页面中的游戏时,这才有效。

这是代码:

FBSDKGameRequestContent *gameRequestContent = [[FBSDKGameRequestContent alloc] init];
     // Look at FBSDKGameRequestContent for futher optional properties
     FBSDKGameRequestDialog *dialog = [[FBSDKGameRequestDialog alloc]init];
     dialog.delegate = self;
     dialog.content = gameRequestContent;
     gameRequestContent.message = @"Become a Ninja!!!";
     gameRequestContent.title = @"NinjaPan";
     dialog.delegate = self;
     dialog.content = gameRequestContent;
     [dialog show];

它的委托方法:

- (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog didCompleteWithResults:(NSDictionary *)results{
if (results) {
      }
}
- (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog didFailWithError:(NSError *)error{
if (error) {
    NSLog(@"%@",error.localizedDescription);
   }
}
- (void)gameRequestDialogDidCancel:(FBSDKGameRequestDialog *)gameRequestDialog{
NSLog(@"Cancelled by user");
}

相关内容

  • 没有找到相关文章

最新更新