我正在创建一个游戏,用户可以使用 FBdialogs 向他的朋友发送请求。我为此使用以下代码。
NSError *error;
NSData *jsonData = [NSJSONSerialization
dataWithJSONObject:@{
@"social_karma": @"5",
@"badge_of_awesomeness": @"1"}
options:0
error:&error];
if (!jsonData) {
NSLog(@"JSON error: %@", error);
return;
}
NSString *giftStr = [[NSString alloc]
initWithData:jsonData
encoding:NSUTF8StringEncoding];
NSMutableDictionary* params = [@{@"data" : giftStr} mutableCopy];
// Display the requests dialog
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:@"Learn how to make your iOS apps social."
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or sending the request.
NSLog(@"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(@"User canceled request.");
} else {
// Handle the send request callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"request"]) {
// User clicked the Cancel button
NSLog(@"User canceled request.");
} else {
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:@"request"];
NSLog(@"Request ID: %@", requestID);
}
}
}
}];
此代码已成功向选定用户发送请求并显示请求 ID。但是当我签入朋友更新时。在他的更新中没有显示任何请求。
谁能告诉我这段代码有什么问题?或者应该有其他方法向朋友发送请求吗?