0

I'm trying to use ASIHTTPRequest. I need request be called in Asynchronous. What I'm trying to do, call this method from my Application, and be able to RETURN BOOL value, was request successed, or not. I was able to do it in Synchronous calls. How is it possible to do? I need somehow, return value to my application, was that call successed or not. My request calls, are in seperate classed, I want keep logic seperate from application. That's why I need be able return somehow value. Thanks for help!

- (BOOL)sendRequest
{
         NSURL* url = [NSURL URLWithString:ServerApiURL];
    __block ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:url];

    [request setCompletionBlock:^
    {

            if ([request responseStatusCode] == 200)
            {
              //NEED SOMEHOW RETURN TRUE IF SUCESSED    
            }       
    }];

    [request setFailedBlock:^
    {
       //NEED RETURN FALSE  
    }];

    [request startAsynchronous];
}}
4

1 回答 1

1

Since you are making asynchronous call, the method can not return a value right away, what you can do instead is to call a callback method in your completion and fail block. For instance, [delegate requestFinishedWithSuccess:YES] or post a notification.

于 2012-04-17T21:37:14.280 回答