2012-05-08 49 views
4

我正在使用FB SDK來允許用戶邀請朋友下載我的應用。我在用戶點擊邀請按鈕時創建一個FB請求。動作看起來是這樣的:在原生iOS應用中使用Facebook SDK邀請多個朋友

- (IBAction)inviteButtonPressed:(UIButton *)sender { 
// create a dictionary for our dialog's parameters 
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity: 7]; 

// set the frictionless requests parameter to "1" 
[params setObject: @"1" forKey:@"frictionless"]; 
[params setObject: @"Test Invite" forKey:@"title"]; 
[params setObject:appID forKey:@"app_id"]; 


[params setObject: @"Test" forKey: @"message"]; 
if([friendsToInvite count] != 0){ 

    [params setObject:friendsToInvite forKey:@"to"]; 

    NSLog(@"%@", params); 
} 

// show the request dialog 
[facebook dialog:@"apprequests" andParams:params andDelegate: nil]; 

} 

的問題是,我通過朋友的陣列(由用戶選擇)的@「到」屬性的對象。這是Facebook的圖書館如何試圖解析@「到」對象(代碼來自Facebook):

 id fbid = [params objectForKey:@"to"]; 
     if (fbid != nil) { 
      // if value parses as a json array expression get the list that way 
      SBJsonParser *parser = [[[SBJsonParser alloc] init] autorelease]; 
      id fbids = [parser objectWithString:fbid]; 
      if (![fbids isKindOfClass:[NSArray class]]) { 
       // otherwise seperate by commas (handles the singleton case too) 
       fbids = [fbid componentsSeparatedByString:@","]; 
      }     
      invisible = [self isFrictionlessEnabledForRecipients:fbids];    
     } 

我的代碼是給我這個錯誤:

-[__NSArrayM UTF8String]: unrecognized selector sent to instance 0x1aea00 
2012-05-08 01:48:29.958 shmob[2976:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM UTF8String]: unrecognized selector sent to instance 0x1aea00' 

當我硬編碼一個單一的應用程序ID進入@「to」對象,它的工作原理!你知道我可以邀請Facebook朋友的名單嗎?

回答

10

實測值的修正:

我使用componentsjoinedbystring轉換的陣列爲字符串,然後設置字符串作爲PARAM爲@「到」屬性。像這樣:

if([friendsToInvite count] != 0){ 

    NSString * stringOfFriends = [friendsToInvite componentsJoinedByString:@","]; 

    [params setObject:stringOfFriends forKey:@"to"]; 

    NSLog(@"%@", params); 
} 

// show the request dialog 
[facebook dialog:@"apprequests" andParams:params andDelegate: nil]; 

工程就像一個魅力。

+0

我們能否確認請求已成功發佈/發送至Facebook Freiend? –

相關問題