1

呼び出して、返されたデータオブジェクトを保存したいフレンドIDの配列があります。

次のようになります。

for (int i = 0; i < self.friendIDArray.count; i++){

            self.detailedRequest = [facebook requestWithGraphPath:[self.friendIDArray objectAtIndex:i] andDelegate:self];
        }

問題は、リクエストを頻繁に送信していて、FBにデータを適切に返す機会を与えていないことだと思いますか?どうすればこれを修正できますか?ありがとう

4

2 に答える 2

1

これがあなたがする必要があることです。これは、NSURLConnection API を使用して非同期リクエストを作成する方法と非常によく似ています。

header/.h ファイルでクラス属性を作成します (メンバー変数、呼びたいものは何でも)

//header/.h file
int indexOfLastFriendLoaded;

実装ファイルで:

- (void) loadFriend:(int) indexOfFriendToLoad {
    [facebook requestWithGraphPath:[self.friendIDArray objectAtIndex:indexOfFriendToLoad] andDelegate:self];
}

//this method is called when each facebook request finishes,
- (void)request:(FBRequest *)request didLoad:(id)result {
    //first do whatever you need to with "result" to save the loaded friend data

    //We make the next request from this method since we know the prior has already completed.
    if (indexOfLastFriendLoaded < [self.friendIDArray count]) {
        [self loadFriend:indexOfLastFriendLoaded];
        indexOfLastFriendLoaded++;
    }   
}

- (void) viewDidLoad {
    //initialize facebook object first

    indexOfLastFriendLoaded = 0;
    [self loadFriend:indexOfLastFriendLoaded];
}
于 2012-04-25T23:57:39.750 に答える
0

リクエスト API は、結果を処理するデリゲートを作成することを提案しています。

https://developers.facebook.com/docs/reference/iossdk/FBRequestDelegate/

于 2012-04-25T23:06:07.527 に答える