How to download a large file with the iPhone SDK and avoid memory usage issues?

前端 未结 3 1877
半阙折子戏
半阙折子戏 2020-12-04 11:26

I\'m using the NSURLConnection class to download a large file in my iPhone application, but it crashes every so often because it\'s using too much memory. I\'m

3条回答
  •  佛祖请我去吃肉
    2020-12-04 12:04

    i'm using

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
        filename = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:save_name];
        NSFileHandle *file1 = [NSFileHandle fileHandleForUpdatingAtPath: filename];
        [file1 writeData: data];
        [file1 closeFile];
    }
    

提交回复
热议问题