I want to implement a UIAlertView
which will show when [[AFHTTPRequestOperationManager manager] GET:]
will start doing its job and will disappear automatically when the job is done. One cool extra feature would be if I could display UIProgressView
with progress of AFHTTPRequestOperation
.
For now I'm checking if a have anything in Core Data and based on that I initialize UIAlertView
:
if (![self coreDataHasEntriesForEntityName:@"Group"]) {
downloadingAlert = [[UIAlertView alloc] initWithTitle:@"Pobieranie" message:@"Trwa pobieranie grup" delegate:nil cancelButtonTitle:@"Anuluj" otherButtonTitles:nil, nil];
[self collectData];
} else {
NSError *error;
[[self fetchedResultsController] performFetch:&error];
}
So to prevent from showing this alert when UITableView
is already filled with data.
As you can see I'm calling this [self collectData]
method which looks like:
-(void)collectData
{
[downloadingAlert show];
[[AFHTTPRequestOperationManager manager] GET:ALL_GROUPS parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSManagedObjectContext *tempContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
tempContext.parentContext = self.moc;
[tempContext performBlock:^{
// Doing something with responseObject
if (![tempContext save:&error]) {
NSLog(@"Couldn't save: %@", [error localizedDescription]);
}
[self.moc performBlock:^{
NSError *error;
if (![self.moc save:&error]) {
NSLog(@"Couldn't save: %@", [error localizedDescription]);
}
[downloadingAlert dismissWithClickedButtonIndex:0 animated:YES];
[self.writer performBlockAndWait:^{
NSError *error;
if (![self.writer save:&error]) {
NSLog(@"Couldn't save: %@", [error localizedDescription]);
}
}];
}];
}];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// Show alert with info about failure
}];
}
As you can see I'm programatically showing this UIAlertView
and dismissing it when downloading is completed and UITableView
is reloaded. But I have no clue how to add UIProgressView
or how to dismiss this UIAlertView
without using dismissWithClickedButtonIndex:
. Any ideas?