4

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

4

1 に答える 1

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

魅力のように機能します。

于 2012-05-09T04:14:00.650 に答える