Tag: 交互

使用AFNetworking下载多个文件时的内存压力问题

在我的应用程序中,我试图下载数以千计的图像(每个图像大小最多3mb)和10个video(每个video大小最大为100mb),并将其保存在文档目录中。 为了实现这一点,我正在使用AFNetworking 在这里,我的问题是, 当我使用一个慢的wifi(约4mbps)成功所有的数据,但同样的下载,如果我正在下一个100mbps的速度与WiFi应用程序正在下载图像和内存下载video时压力问题,然后应用程序崩溃 。 -(void) AddVideoIntoDocument :(NSString *)name :(NSString *)urlAddress{ NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlAddress]]; [theRequest setTimeoutInterval:1000.0]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:theRequest]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:name]; operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Successfully downloaded file to %@", path); } failure:^(AFHTTPRequestOperation *operation, […]