FBRequestDelegate didReceiveResponse how to find out what request this response is for

I use the latest iphone sdk on facebook, I make several facebook requests from different places in my application. The calls to didReceiveResponse and didLoad are called for all of them, it is very difficult to find the didLoad method which for which request this answer was such that I wonder if didReceiveResponse can help, can I get some information in this method that will tell me that it was request for which I received a response.

+4
source share
4 answers

All I do here is check the unique attribute in the response and bind it to the request, I know that this is not the best way to do, but this is what I have found so far, please let me know if someone does it differently

0
source

The way I do this is almost the same as Ziminji does, but in the 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 only need to check the URL to which you sent the request, and you can also check the parameters for this request. Then you can distinguish one from the other.

+1
source

You can 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]; } } } 
0
source

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

 - (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]; } } 
0
source

Source: https://habr.com/ru/post/1342325/


All Articles