我正在使用一种方法来下载文档目录中的视频文件,它工作得非常好,我使用下面的代码在后台下载视频,但是在下载时我需要更新进度条,因为下载了多少,但是主线程是不更新。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data = [NSData dataWithContentsOfURL: videoURL];
NSString *pathToDocs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = [NSString stringWithFormat:@"%@.mp4",self.titleString];
[data writeToFile:[pathToDocs stringByAppendingPathComponent:filename] atomically:YES];
NSLog(@"File %@ successfully saved", filename);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Succesfully Downloaded" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
});