我正在编写一个 IOS 文件上传应用程序,它NSUrlConnection
一次打开多个(每个文件上传一个文件),并希望为每个文件实现相应的进度条。
NSUrlConnection
文件上传片段:
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:request
delegate:self
[urlConnection start];
更新进度条的委托方法:
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite {
self.progressBar.progress += (float)bytesWritten/(float)totalBytesExpectedToWrite;
NSLog(@"it's working: %lf",self.progressBar.progress);
}
现在在这种情况下,如果我为每个文件上传都有一个单独的进度条,有没有办法知道哪个文件上传,即NSURLConnection
这个委托对应于哪个,以便我可以相应地更新正确的进度条。是否有任何我可以设置的属性,我可以NSURLConnection
在委托方法中访问连接变量?
谢谢。