如何控制任务创建maxConcurrentOperationCount

时间:2016-04-16 06:46:45

标签: ios objective-c iphone nsurlsession nsurlsessiondownloadtask

 - (NSURLSession *)session{
        if (!_session) {
            NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];

            _session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]];

        }
        return _session;
    }


-(void)start {
            NSURL *url = [NSURL URLWithString:@"http://192.168.2.7:8080/Music/movie.mp4"];
            self.task =   [self.session downloadTaskWithURL:url];
            [self.task resume];
    }

- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location{
    NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:downloadTask.response.suggestedFilename];
    NSFileManager *fm = [NSFileManager defaultManager];
    [fm moveItemAtURL:location toURL:[NSURL fileURLWithPath:filePath] error:nil];
}

当我[自我开始]占用大量记忆并创造了很多理论时

enter image description here enter image description here 如何通过控制较少的内容来减少内存使用?

0 个答案:

没有答案