I am using this block method to load my data from the server...
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[myString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection
sendAsynchronousRequest:urlRequest
queue:queue
completionHandler: ^( NSURLResponse *response,
NSData *data,
NSError *error)
{
[[mySingleton dictionaryUserDetail] removeAllObjects];
[[mySingleton arrayUserDetail] removeAllObjects];
if ([data length] > 0 && error == nil) // no error and received data back
{
NSError* error;
NSDictionary *myDic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
[mySingleton setDictionaryUserDetail:[myDic mutableCopy]];
NSArray *myArray = [myDic objectForKey:@"searchResults"];
[mySingleton setArrayUserDetail:[myArray mutableCopy]];
dispatch_async(dispatch_get_main_queue(), ^{
[self userDetailComplete];
});
} else if
([data length] == 0 && error == nil) // no error and did not receive data back
{
dispatch_async(dispatch_get_main_queue(), ^{
[self serverError];
});
} else if
(error != nil) // error
{
dispatch_async(dispatch_get_main_queue(), ^{
[self serverError];
});
}
}];
I would like to be able to show the user a progress bar instead of just a spinner. If I were using delegates I assume I could have used the NSURLConnectionDelegate
connection:didReceiveData:
but I do not know how to do this with a block. Anyone have some genius insight?