Crashes while fetching data from filepath

这一生的挚爱 提交于 2019-12-10 12:12:10

问题


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

  1. URL is perfect (Checked logs)
  2. File exists at that path (checked path)

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.


回答1:


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.



来源:https://stackoverflow.com/questions/11016247/crashes-while-fetching-data-from-filepath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!