Manish Agrawal
Manish Agrawal

Reputation: 11026

send Synchronous request using ASIHTTPREQUEST libraries showing activity indicator in iPhone

I want to show activity indicator while sending and receiving synchronous asihttprequest from server. I have used activity indicator as the asihttprequest is send but it did not showing in iPhone due to synchronous request.
Any suggestion how to show activity indicator during synchronous data transfer.
Thanks

Upvotes: 1

Views: 907

Answers (1)

Cyprian
Cyprian

Reputation: 9453

Synchronous request calls your activity indicator delegate method setProgress: on the main thread.

B/c you are using ASIHTTPRequest on the main thread you are blocking the UI, hence calls to setProgress: are queuing to be dispatched after the request is finished, but by that time the progress is already 100%

To solve this use either asynchronous request or call synchronous request on a background thread using

[self performSelectorInBackground:@selector(startSynchronous:) withObject:nil];

Edit

Remember to create your own autorelease pool to handle the memory inside your startSynchronous: method

-(void)startSynchronous:(BOOL)animate{
       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

       NSString *autoreleasedString = @"xxx";   

       NSLog(@"%@",autoreleasedString);

       [pool drain];

}

Upvotes: 2

Related Questions