objectiveflickr icon indicating copy to clipboard operation
objectiveflickr copied to clipboard

delegate callback doesn't get called when call callAPIMethodWithGET

Open MelvinTo opened this issue 12 years ago • 8 comments

and if I manually set the shouldWaitUntilDone to YES before performing the http request, the callback can be called successfully.

MelvinTo avatar May 18 '12 09:05 MelvinTo

    if (requestURL) {
        [HTTPRequest setContentType:nil];
  +    [HTTPRequest setShouldWaitUntilDone:YES];
        return [HTTPRequest performMethod:LFHTTPRequestGETMethod onURL:requestURL withData:nil];        
    }
    return NO;

MelvinTo avatar May 18 '12 09:05 MelvinTo

IOS 5.1 ARC enabled, link objectiveflickr as static library, this is how i use objectiveflickr. (most copied from the sample code)

the flickrAPIRequest callback doesn't get called.

- (RocoFlickrPhoto *) init {
    flickrAPIContext = [[OFFlickrAPIContext alloc] initWithAPIKey:FLICKR_API_KEY sharedSecret:FLICKR_API_SHARED_SECRET];
    flickrRequest = [[OFFlickrAPIRequest alloc] initWithAPIContext:flickrAPIContext];

    [flickrRequest setDelegate:self];

    return self;
}

- (void) flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary {
    NSDictionary *photoDict = [[inResponseDictionary valueForKeyPath:@"photos.photo"] objectAtIndex:0];

    NSString *title = [photoDict objectForKey:@"title"];
    if (![title length]) {
        title = @"No title";
    }

    NSURL *photoSourcePage = [flickrAPIContext photoWebPageURLFromDictionary:photoDict];    

}

- (RocoPhoto *) getRecentPhoto {
    if (![flickrRequest isRunning]) {
        BOOL result = [flickrRequest callAPIMethodWithGET:@"flickr.photos.getRecent" arguments:[NSDictionary dictionaryWithObjectsAndKeys:@"1", @"per_page", nil]];
    }

    return nil;
}

MelvinTo avatar May 18 '12 09:05 MelvinTo

seems a bug of Xcode.

MelvinTo avatar May 18 '12 10:05 MelvinTo

not a bug of Xcode.

MelvinTo avatar May 18 '12 10:05 MelvinTo

Have the same issue.

Thanks @MelvinTo for the + [HTTPRequest setShouldWaitUntilDone:YES];, but it seems that this issue is present and should be resolved. Do anyone have any thoughts on this?

tar500 avatar Apr 17 '14 23:04 tar500

Found a problem and a solution: a request object had been autoreleased before it received any response, so just own that request either by adding to an array or capturing it with a strong pointer and everything will be ok.

It also explains why [HTTPRequest setShouldWaitUntilDone:YES] worked.

tar500 avatar Apr 17 '14 23:04 tar500

I was having this problem. This identified the issue. The class that was using the ObjectiveFlickr and making the API calls was held weakly within a block. Once the block finished, the instance was lost and, with it, the API call, delegate callbacks, etc. When I specified __strong __weak for that instance, it all worked again.

        __strong __block HuFlickrServicer *servicer;
        UITapGestureRecognizer *doubleTap = [UITapGestureRecognizer bk_recognizerWithHandler:^(UIGestureRecognizer *sender, UIGestureRecognizerState state, CGPoint location) {
            LOG_UI(0, @"Double tap.");
            servicer = [[HuFlickrServicer alloc]init];
            [servicer like];
        }];

bleeckerj avatar Jun 02 '14 22:06 bleeckerj

@property (nonatomic,strong) OFFlickrAPIRequest *flickrRequest; ... ...

if (requestURL) { [HTTPRequest setContentType:nil]; + [HTTPRequest setShouldWaitUntilDone:YES];
return [HTTPRequest performMethod:LFHTTPRequestGETMethod onURL:requestURL withData:nil]; }

i add this line code marked by '+' ,but the callback can not be called!!

ikallen avatar Sep 11 '15 04:09 ikallen