我使用一種方法下載文件目錄內的視頻文件,它工作得很好,我使用下面的代碼,它是在後臺下載視頻,但下載時需要更新進度條也是多少下載,但主線程沒有更新。如何從UIProgressBar在iOS主線程上更新
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];
});