- (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];
}
当我[自我开始]占用大量记忆并创造了很多理论时