实际上我需要在我的应用程序中添加应用程序请求概念。为此,我使用了以下代码:
[FBWebDialogs
presentRequestsDialogModallyWithSession:[FBSession activeSession]
message:@"Try this app"
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(@"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(@"User canceled request.");
} else {
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"request"]) {
NSLog(@"User canceled request.");
} else {
NSString *requestID = [urlParams valueForKey:@"request"];
NSLog(@"Request ID: %@", requestID);
}
}
}
}];
- (NSDictionary*)parseURLParams:(NSString *)query
{
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val =
[kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
}
return params;
}
我还查看了这个 facebook 文档App requests
但是当我向我的任何朋友发送请求时,我得到了请求 ID,但该通知没有出现在我朋友的 Facebook 帐户上。我对上面的代码做错了什么?