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

时间:2015-06-05 03:58:28

标签: ios facebook-graph-api facebook-invite-friends

我有完整的发送邀请代码,当我点击按钮弹出菜单出现时,弹出菜单说...

  

ERROR。

     

游戏请求适用于游戏。

邀请朋友的

代码就在这里:

 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];


}

所以我错了? 请帮我。 感谢。

2 个答案:

答案 0 :(得分:1)

好的,我了解您是否要向朋友发送应用请求,而不是使用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,请参阅此link

它的委托方法:

- (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];
   }
}

答案 1 :(得分:0)

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

注意:仅当您的应用类别为Facebook开发者页面中的游戏时,此功能才有效。

以下是代码:

SELECT courier
  FROM Deliveries
 WHERE STR_TO_DATE(pickup_date, '%m/%d/%Y') > '2015-05-17' OR STR_TO_DATE(pickup_date, '%m/%d/%Y') < '2015-05-16' ;

它的委托方法:

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];