FBRequestDelegate didReceiveResponse 如何找出此响应的请求

发布于 2024-10-20 20:48:40 字数 204 浏览 0 评论 0原文

我正在使用 facebook 最新的 iphone sdk,我从应用程序中的不同位置向 facebook 发出多个请求。对于所有这些 didReceiveResponse 和 didLoad 方法都被调用,很难从 didLoad 方法中找出这个响应是什么请求,所以我想知道 didReceiveResponse 是否可以提供帮助,我可以在这个方法中检索一些信息来告诉我什么是我已得到答复的请求。

I am using facebook latest iphone sdk, I am making multiple request to facebook from different places in my app. For all of them didReceiveResponse and didLoad methods get called, it is very difficult to find out from didLoad method that for what request this response was so I am wondering if didReceiveResponse can help, can i retrieve some information in this method which will tell me what was the request for which I have got the response.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

执妄 2024-10-27 20:48:40

我的做法与 Ziminji 的做法几乎相同,但在 didLoad 方法中:

- (void)request:(FBRequest *)request didLoad:(id)result
{
    NSLog(@"Facebook request %@ loaded", [request url]);

    //handling a user info request, for example
    if ([[request url] rangeOfString:@"/me"].location != NSNotFound)
    {
        /* handle user request in here */
    }
}

所以基本上你只需要检查你发送请求的 url,你还可以检查该请求的参数。然后您就可以将其中一个与另一个区分开来。

The way I do it is pretty much the same way Ziminji does it, but in didLoad method:

- (void)request:(FBRequest *)request didLoad:(id)result
{
    NSLog(@"Facebook request %@ loaded", [request url]);

    //handling a user info request, for example
    if ([[request url] rangeOfString:@"/me"].location != NSNotFound)
    {
        /* handle user request in here */
    }
}

So basically you need only to check the url you sent the request to, and you can also check the parameters for that request. Then you can differentiate one from another.

£烟消云散 2024-10-27 20:48:40

我在这里所做的就是检查响应中的某些唯一属性并将其与请求相关联,我知道这不是最好的方法,但这是我迄今为止发现的,请告诉我如果任何人都在做不同的事情

All I am doing here is I am checking for some unique attribute in the response and relating it to the request, I know this is not the best way to do is, but this is what I have found so far, please let me know if any one is doing it any different

月亮坠入山谷 2024-10-27 20:48:40

您可以尝试如下操作:

- (void) request: (FBRequest *)request didReceiveResponse: (NSURLResponse *)response {
    NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
    if (statusCode == 200) {
        NSString *url = [[response URL] absoluteString];
        if ([url rangeOfString: @"me/feed"].location != NSNotFound) {
            NSLog(@"Request Params: %@", [request params]);

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Facebook" message: @"Message successfully posted on Facebook." delegate: nil cancelButtonTitle: @"OK" otherButtonTitles: nil];
            [alert show];
            [alert release];
        }
    }
}

You could try something like the following:

- (void) request: (FBRequest *)request didReceiveResponse: (NSURLResponse *)response {
    NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
    if (statusCode == 200) {
        NSString *url = [[response URL] absoluteString];
        if ([url rangeOfString: @"me/feed"].location != NSNotFound) {
            NSLog(@"Request Params: %@", [request params]);

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Facebook" message: @"Message successfully posted on Facebook." delegate: nil cancelButtonTitle: @"OK" otherButtonTitles: nil];
            [alert show];
            [alert release];
        }
    }
}
高跟鞋的旋律 2024-10-27 20:48:40

如果您在创建请求对象时将请求对象保留为请求委托的属性,则可以检查它是否与委托方法调用匹配。例如:

- (void)queryForUserInfo {
   self.userInfoRequest = [facebook requestWithGraphPath:@"me" andDelegate:self];
}


#pragma mark <FBRequestDelegate>

- (void)request:(FBRequest *)request didLoad:(id)result {
    if (request == self.userInfoRequest) {
       [self handleUserInfoResult:result];
    }
}

If you retain the request object as a property of your request delegate when you create it, you can check to see if it matches on the delegate method calls. For example:

- (void)queryForUserInfo {
   self.userInfoRequest = [facebook requestWithGraphPath:@"me" andDelegate:self];
}


#pragma mark <FBRequestDelegate>

- (void)request:(FBRequest *)request didLoad:(id)result {
    if (request == self.userInfoRequest) {
       [self handleUserInfoResult:result];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文