我想实现一个 UIAlertView
,它将显示 [[AFHTTPRequestOperationManager manager] GET:]
何时开始执行其工作,并在工作完成后自动消失。一个很酷的额外功能是,如果我可以显示 UIProgressView
以及 AFHTTPRequestOperation
的进度。
现在我正在检查 Core Data 中是否有任何内容,并基于此初始化 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];
}
因此,为了防止在 UITableView
已填充数据时显示此警报。
如您所见,我正在调用这个 [self collectData]
方法,它看起来像:
-(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
}];
}
如您所见,我以编程方式显示此 UIAlertView
并在下载完成并重新加载 UITableView
时关闭它。但我不知道如何添加 UIProgressView
或如何在不使用 dismissWithClickedButtonIndex:
的情况下关闭此 UIAlertView
。有什么想法吗?
最佳答案
AFNetworking 2.0 HTTP POST Progress
如果您将使用以下方法,您可以收到进度信息
- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
fromData:(NSData *)bodyData
progress:(NSProgress * __autoreleasing *)progress
completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler
AFHTTPSessionManager 类
关于ios - 带有渐进式 UIAlertView 的 AFNetworking 下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22133405/