我正在使用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库试图解析@“到”对象(来自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'
当我将单个app id硬编码到@“to”对象中时,它可以工作!你知道如何邀请Facebook好友列表吗?
答案 0 :(得分: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];
像魅力一样。