从文件路径获取数据时崩溃 [英] Crashes while fetching data from filepath
问题描述
只有大型档案(大于100 MB),才会尝试从路径/网址(仅储存在文件资料夹中的影片档案)撷取资料。
:iOS(4.3),iPad 1
- 网址是完美的
- URL is perfect (Checked logs)
- File exists at that path (checked path)
注意:仅在设备上崩溃。
下面是应用程序崩溃的代码:
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。
我不认为
您需要花费很长时间,应用程式会被杀。
是在启动时这样做。
The app crashes while trying to fetch data from path/URL (video file stored in documents folder) only for large files (>100 MB).
Device Details: iOS (4.3), iPad 1
Note: Crashes on device only.
Below is the code where app crashes:
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]);
Any comments.
It seems you are running out of memory.
On the device there is normally far less memory available that your simulator and 100MB is a lot to be storing in RAM. Consider breaking the downloadable files into smaller chunks and deal with them in pieces if you can.
I don't think
You are taking to long time and the app gets killed.
as David suggests unless you are doing this on start up.
这篇关于从文件路径获取数据时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!