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の友達のリストを招待する方法を知っていますか?