【发布时间】:2015-10-05 18:35:08
【问题描述】:
我想在我的文件夹中保存一个 mp4 视频,但是当我再次打开该应用程序时,该文件为零。但是当我保存文件时,我可以打开它,所以它似乎从文件夹中消失了。
保存:
NSData *videoData = [NSData dataWithContentsOfURL:exportUrl];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *tempPath = [documentsDirectory stringByAppendingFormat:@"/%@",videoName];
self.path_video_to_save = tempPath;
BOOL success = [videoData writeToFile:tempPath atomically:YES];
if (success)
NSLog(@"saved");
else
NSLog(@"not saved!!!!!!!!!!!!!!");
我得到了真正的成功,所以没关系,我可以很好地播放我的视频。
NSString *path_video = [dict objectForKey:@"path"]; //dictionary where I save the path, the same before and after closing app
NSData *videoData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:path_video]];
if (videoData == nil){
NSLog(@"DATA NULL");
}
else
NSLog(@"DATA OK");
NSLog(@"PATH:%@", path_video);
self.player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path_video]];
在这一点上它工作正常。
但是当我关闭并再次打开应用程序并获得路径时,我的应用程序崩溃并且我有日志“DATA NULL”我不明白为什么当我关闭我的应用程序时文件消失了......这是怎么回事?
谢谢
【问题讨论】:
-
您使用的是设备还是模拟器? Ofc 我建议在真机上试用。
-
我用的是真机... iPhone 5s
-
好的,我刚刚在 iPad 上试了一下,它运行良好,我的 iPhone 发生了什么?
-
我猜这是另一个问题 ;) (笑话)你的 iPhone 有足够的磁盘空间吗?我建议不要自动尝试写入数据(它会直接写入您的路径而不是首先写入 RAM,只是为了进行测试检查)
-
收到
YES并不意味着它运行良好。在调用中传递一个 NSError 指针,如果不是nil,则尝试NSLogNSError 的localizedDescription。
标签: ios file ios8 nsdocumentdirectory