How to change NSURLConnection's priority?

喜欢而已 提交于 2020-01-04 08:16:14

问题


I'm working on a music app, which use ASIHTTPRequest to access to server's api, and use NSURLConnection to download music files.

One music file is 10M or so. When downloading music file, access to server's api will be much more slow than not downloading music file.

So I want to change download connection's priority lower. But there is no API to change priority of NSURLConnection or NSURLRequest.

How to archive this?


回答1:


I think only NSOperationQueues can be priorized. Here is a link to an example: http://eng.pulse.me/tag/nsurlconnection/

An alternative would be, to stop downloading the music file an resume it after your other downloads are completed. To do this you could tell ASIHTTP to save a download to a file and resume it on request.

Here is an example from one of my projects:

- (void) executeFileDownloadAtURL:(NSURL *) aURL toDirectory:(NSString *) aDestinationPath;
{
    self.request = [ASIHTTPRequest requestWithURL:aURL];
    [self.request setDownloadDestinationPath:aDestinationPath];
    self.request.downloadProgressDelegate = self.delegate;
    [self.request setAllowResumeForFileDownloads:YES];
    NSString *tmpDir = NSTemporaryDirectory();
    NSString *tempFilePath = [NSString stringWithFormat:@"%@%@", tmpDir, @"TempMovie.mp4"];
    [self.request setTemporaryFileDownloadPath:tempFilePath];
    self.request.showAccurateProgress = YES;
    self.request.delegate = self;
    [self.request startAsynchronous];
}


来源:https://stackoverflow.com/questions/14918800/how-to-change-nsurlconnections-priority

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!