应用程序在尝试从路径/URL(存储在文档文件夹中的视频文件)获取大文件(>100 MB)数据时崩溃。
设备详细信息:iOS (4.3)、iPad 1
- URL 完美(已检查日志)
- 文件存在于该路径(选中路径)
注意:仅在设备上崩溃。
下面是应用程序崩溃的代码:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
if ([paths count] > 0)
{
filePath = [paths objectAtIndex:0];
filePath = [filePath stringByAppendingPathComponent:@"Private Documents"];
filePath = [filePath stringByAppendingPathComponent:@"videos"];
filePath = [filePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4",st]];
}
NSURL *fileUrl=[NSURL fileURLWithPath:filePath];
NSMutableData *Data = [NSMutableData dataWithContentsOfURL:fileUrl]; //CRASHES ON THIS LINE
NSLog(@"Data: %d",[Data length]);
任何评论。
最佳答案
看来你的内存不足了。
在设备上,可用内存通常比您的模拟器少得多,100MB 的内存足以存储在 RAM 中。如果可以,请考虑将可下载文件分成更小的 block 并分段处理。
我不认为
You are taking to long time and the app gets killed.
正如 David 所建议的,除非您在启动时这样做。
关于ios - 从文件路径获取数据时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11016247/