简体   繁体   中英

Convert large data to NSData

I am storing a video file of size more than 1 GB and storing into homeDirectory. I am trying to convert into NSData object as follows

NSData *videoData = [[NSData alloc] initWithContentsOfFile:filePath];

but here I am getting video data as nil. When I tried for video of 500 MB it is working fine.

Is there any limitation on size while converting into NSData?

Try using this (requires iOS 5.0 or later):

NSError *error = nil;
NSData *data = [[NSData alloc] initWithContentsOfFile:filePath
                                              options:NSDataReadingMappedIfSafe
                                                error:&error];

Prior to iOS 5.0 you can use:

NSData *data = [[NSData alloc] initWithContentsOfMappedFile:filePath];

These will map the file into virtual memory if it is safe, which will significantly reduce the amount of memory used overall.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM