我正在使用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];
}
问题是我正在为@"to"属性的对象传递一个朋友数组(由用户选择)。 这就是Facebook库尝试解析@"to"对象(来自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好友列表吗?
找到了修复程序:
我使用 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];
就像一个魅力。