2013-04-22 133 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