我有一个UITabBarController
其中UITableViewControllerA列表文件和UITableViewContollerB显示正在上传的文件的进度。AFNetworking多个上传减慢主线程
我有一个Singleton类的上传方法,调用我的子类AFHTTPClient
并使用NSNotificationCenter
来通知我的UITableViewControllerB的上传进度。但目前的这种方式正在减慢用户界面到几乎无法使用的地步,我不知道如何改进这一过程。我读过AFNetworking回调函数在主线程上调用。速度较慢的UI响应是否来自我的NSNotificationCenter?
我也想提一下我在模拟器上运行这个。
从我的Singleton类的方法。
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:uniqueName forKey:@"unique"];
[dict setObject:[NSNumber numberWithFloat:0] forKey:@"progress"];
[self.active addObject:dict];
[[CustomHTTP client] uploadFileName:@"filename" withBytes:data toPath:serverPath progress:^(float progress) {
[dict setObject:progress forKey:@"progress"];
NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
[info setObject:[NSNumber numberWithInt:[self getIndexByUniquename:uniqueName]] forKey:@"row"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"ProgressNotification" object:self userInfo:info];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
} andFailure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
UITableViewControllerB.m
- (void) receiveTestNotification:(NSNotification *) notification {
if ([[notification name] isEqualToString:@"ProgressNotification"]) {
NSDictionary *dict = notification.userInfo;
int row = [[dict objectForKey:@"row"] intValue];
self.inProgress = [Transfer defaultTransfer].active;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
}
您同时运行多少个上传?使用仪器来查看发生了什么。 – Wain
@我当时正在运行2上传30MB +。我应该使用哪种仪器? –
使用范围,检查处理器使用情况(时间分析)和内存使用情况。 2同时上传应该没问题。您获得了多少进度更新。 – Wain