2

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?

4

1 回答 1

1

我认为只有 NSOperationQueues 可以优先。这是一个示例的链接: http: //eng.pulse.me/tag/nsurlconnection/

另一种方法是停止下载音乐文件,并在其他下载完成后恢复它。为此,您可以告诉 ASIHTTP 将下载保存到文件并根据请求恢复。

这是我的一个项目中的一个示例:

- (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];
}
于 2013-02-19T08:19:44.730 回答