iphone开发:如何处理fbwebdialogs弹出按钮

时间:2013-05-29 19:19:01

标签: iphone ios objective-c facebook dialog

在我的应用程序中,我使用FBWebDialogs向Facebook朋友发送应用程序请求,我成功了。我的问题是我无法处理FBWebDialogs弹出窗口按钮。在下面的代码中,我可以检测到X按钮和取消按钮但是当我选择发送按钮时它仍然给出日志NSLog(@"User canceled request.");我正在使用facebook文档中给出的代码。我的错是什么?

[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);
                     }
                 }
             }
         }];

我有像这样的parseURLParams函数:

- (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 objectAtIndex:1]
         stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        [params setObject:val forKey:[kv objectAtIndex:0]];
    }
    return params;
}

1 个答案:

答案 0 :(得分:1)

我发现这是一个常见问题,因为SDK 3.5中存在错误,所以我将sdk从3.5更新到3.5.1并解决了问题。