0
當我開始使用NSURLSessionDataTask下載文件時,進度無法運行一段時間。然後完成下載後,只顯示全藍進度條。當我使用NSURLSessionDataTask下載任務時,進度條無法正常工作?
我的代碼
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler
{
completionHandler(NSURLSessionResponseAllow);
NSLog(@"Response:%@ \n", response);
self.progressView.progress=0.0f;
self.downloadSize=[response expectedContentLength];
self.dataToDownload=[[NSMutableData alloc]init];
}
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
[self.dataToDownload appendData:data];
self.progressView.progress=[ self.dataToDownload length ]/_downloadSize;
}
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
didCompleteWithError:(NSError *)error {
if (error) {
// Handle error
}
else {
}
這些都是我用來實現代碼。
thanxx..itz工作 –
如何添加簡歷和取消下載 –
考慮恢復,取消和暫停方法 https://developer.apple.com /library/prerelease/ios/documentation/Foundation/Reference/NSURLSessionTask_class/index.html#//apple_ref/occ/instm/NSURLSessionTask/suspend ps:給我一個刻度標記,如果我的解決方案有效,非常感謝。 –