2013-04-22 149 views
8

我想邀请Facebook的用户尝试我的iOS应用程序(这不是在商店,还没有完成它)。从Facebook的iOS应用程序邀请Facebook用户:邀请没有被发送

我使用Facebook的API来验证用户,然后尝试使用下面的代码:

- (void)shareWithFriends:(id)sender 
{ 
    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:@"Invite Friends" 
          message:@"If you enjoy using this app, would you mind taking a moment to invite a few friends that you think will also like it?" 
          delegate:self 
          cancelButtonTitle:@"No Thanks" 
          otherButtonTitles:@"Tell Friends!", nil]; 
    [alert show]; 
} 

- (void)alertView:(UIAlertView *)alertView 
didDismissWithButtonIndex:(NSInteger)buttonIndex { 
    if (buttonIndex == 0) { 
     // User has clicked on the No Thanks button, do not ask again 
     NSLog(@"Chitty user says he doesn't wanna share"); 
    } else if (buttonIndex == 1) { 
     // User has clicked on the Tell Friends button 
     [self performSelector:@selector(sendRequest) withObject:nil afterDelay:0.5]; 
    } 
} 

- (void)sendRequest { 
    // Display the requests dialog 

    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil]; 
    [FBWebDialogs presentRequestsDialogModallyWithSession:nil 
                message:[NSString stringWithFormat:@"Try this app, brah!"] 
                title:nil 
               parameters:params 
                handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) { 
                 if (error) { 
                  // Case A: Error launching the dialog or sending request. 
                  NSLog(@"Error sending request."); 
                 } else { 
                  if (result == FBWebDialogResultDialogNotCompleted) { 
                   // Case B: User clicked the "x" icon 
                   NSLog(@"User canceled request."); 
                  } else { 
                   NSLog(@"Request Sent."); 
                  } 
                 }}]; 


} 

然而,当我选择的用户我想发送的邀请到谁,然后点击发送。什么都没发生。我确实收到了“请求已发送”。通过NSLog,但我的朋友没有收到它。

任何想法?

回答

0

你什么时候填充参数?

我知道FB API亲切发送一个完成的动作,如果你发送一个空白的Facebook用户名作为收件人

4

我注意到,通知消息仅在Facebook的应用程序同时在Android/iOS版即将到来,但网络用户可以”没有看到它,我希望它不是来自Facebook的实施?另外为了确保你的inviation(s)被成功发送,你必须解析resultURL查询。

NSDictionary *parameters = @{@"to":@""}; 

[FBWebDialogs presentRequestsDialogModallyWithSession:nil 
                 message:SL_FB_INVITE_DESCRIPTION 
                 title:SL_FB_INVITE_TITLE 
                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] autorelease]; 
       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]; 

- (NSDictionary *)parseURLParams:(NSString *)query 
{ 
    NSArray *pairs = [query componentsSeparatedByString:@"&"]; 
    NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease]; 
    for (NSString *pair in pairs) 
    { 
     NSArray *kv = [pair componentsSeparatedByString:@"="]; 

     [params setObject:[[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] 
        forKey:[[kv objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
    } 

    return params; 
} 
0

你怎么知道你的请求还没有达到其他用户? 您必须知道他们不会收到任何通知,他们可以通过访问this链接访问它:

您必须在您的应用中拥有一个Facebook应用,作为具有画布页面的平台。然后用户会收到通知。

0

它总是取决于您的应用程序所在的平台。例如:如果您的应用只能在移动设备上使用,那么受邀的朋友只会在手机上看到该请求,而不会在facebook.com上看到该请求。如果您在facebook.com上也有画布应用程序,它也会出现在facebook.com上。

您可以在关于应用程序发送的请求“接收体验”[1]的文档中阅读更多关于它的信息。

[1] https://developers.facebook.com/docs/games/requests/v2.0#receive