在原生iOS应用中使用Facebook SDK邀请多个朋友

ios*_*oob 4 mobile facebook facebook-graph-api ios ios5

我使用FB SDK允许用户邀请朋友下载我的应用程序.我在用户点击邀请按钮时创建了FB请求.该动作如下所示:

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

}
Run Code Online (Sandbox Code Playgroud)

问题是我正在传递一组朋友(由用户选择)作为@"to"属性的对象.这就是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];             
        }
Run Code Online (Sandbox Code Playgroud)

我的代码给了我这个错误:

-[__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'
Run Code Online (Sandbox Code Playgroud)

当我将单个应用程序ID硬编码到@"to"对象中时,它可以工作!你知道如何邀请Facebook好友列表吗?

ios*_*oob 10

找到修复:

我使用componentsjoinedbystring将数组转换为字符串,然后将字符串设置为@"to"属性的参数.像这样:

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];
Run Code Online (Sandbox Code Playgroud)

奇迹般有效.