iPhone开发: how to handle fbwebdialogs pop-up buttons

标签 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;
}

最佳答案

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

关于iPhone开发: how to handle fbwebdialogs pop-up buttons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16822148/

相关文章:

iphone - 如何实现 uislider 以便它可以用作 AVQueueplayer 中的洗涤器

objective-c - 在 Swift 项目中使用 Objective-C 文件。在桥接头中导入头文件导致 `#import "Module-Swift.h"` 失败

ios - 将新的 xib 连接到继承自 UIView 的类

ios - 如何为 UIDatePickerView 设置时间间隔?

iphone - 根据两个图像之间的差异创建蒙版 (iPhone)

ios - Swift3 - 单例共享 UItextfield 值不更新第二次

ios - 数组更改时 SwiftUI 列表不更新

objective-c - objective-c :如何将sqlite3数据库存储在应用程序文件夹之外?

ios - 如何在 TabBar 应用程序中强制执行方向

iphone - 检测 iOS 应用程序是否在调试器中运行