这里是东西,我得到了一些代码,不执行(编译运行的代码,但什么都不做)......这里是代码...使用NSURLSessionDelegate
和[NSOperationQueue mainQueue] addOperationWithBlock
为什么不NSOperationQueue执行与addOperationWithBlock提交了块?
@interface tablaPosViewController : UIViewController <NSURLSessionDelegate>
@end
@implementation tablaPosViewController()
- (void)viewDidLoad
{
//some code to set the view, labels and stuff
[self downloadTheHTMLdata] // this code download some data from WWW
}
- (void)downloadTheHMTLdata
{
//some code to set the session using an object
[object.downloadTask resume]; //Begins the download
}
- (void)toFixTablaPosiciones
{
//some code to do with the downloaded data from WWW (and HTML sheet)
//here, parse the HTML Sheet, and put some data into an Arrays, and another public vars
//call another method
[self PutTheDataInLabel];
}
- (void)PutTheDataInLabel
{
//some code to put all the data in every label
//take the public vars that was set in the previous method, and do some code with it
//and put the info into the labels
//call another method
[self MoreStuff];
}
- (void)MoreStuff
{
//some code..
}
-(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
{
//When the download finish this method fire up!
//this is to copy file from tmp folder to Docs folder
if ([fileManager fileExistsAtPath:[destinationURL path]])
{
[fileManager removeItemAtURL:destinationURL error:nil];
}
BOOL success = [fileManager copyItemAtURL:location //TMP download folder
toURL:destinationURL //Documents folder
error:&error];
//HERES COMES THE TROUBLE!!!
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self toFixTablaPosiciones]; //Call this method, that has other method calls!
}];
}
@end
UPDATE
此队列中的另一个代码put方法...
-(void)URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session{
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[self.session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
if ([downloadTasks count] == 0) {
if (appDelegate.backgroundTransferCompletionHandler != nil) {
void(^completionHandler)() = appDelegate.backgroundTransferCompletionHandler;
appDelegate.backgroundTransferCompletionHandler = nil;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
completionHandler();
}];
}
}
}];
}
的问题是,当下载文件结束,调用-(void)URLSession:(NSURLSession *)session downloadTask:...
方法,我等待[[NSOperationQueue mainQueue] addOperationWithBlock:^{...
运行è东西......但它不执行任何[self toFixTablaPosiciones]
!!。
我跑的代码一步一步,我看怎么编译运行所有的代码,在法法......但鉴于从未更新,运行,但不执行,根本就做什么,我有一个活动指标,并且想要阻止它,但是这些标签仍然具有demumie数据,活动指标永远不会停止并且永不消失。 在之前的视图中,我使用类似的类下载了另一个文件,并且下载得非常快。将这种观点/类尝试进行下载,这是事情...
希望能任何机构可以帮助我,给我的任何建议。谢谢!
你在主线程上更新UI? – Joel 2014-09-01 15:56:14
是的,这是完整的类,它与视图一起工作,我使用viewDidLoad以dummie数据设置视图,并在下载完成后用主线程上的正确数据更新所有标签(用户正在看到的) – 2014-09-01 16:03:01
主操作队列是一个串行队列。一次只能运行一个操作。这是您将操作添加到该队列的唯一位置吗?或者你添加其他操作?他们中的任何一个都跑了很长时间还是阻止等待其他东西来完成? – 2014-09-01 16:54:56