NSURL 文件URLWithPath:isDirectory:无法正常工作



我想做的只是从iPhone访问本地文件系统。我在Library目录中有一些文件。

所以,我的代码如下。

NSString *dir = @"/Users/MY_ID/Library/Application Support/iPhone Simulator/5.0/Applications/6AB76439-APP-ID-1C1BB92E/Library/test";
NSURL *url = [NSURL fileURLWithPath:dir isDirectory:NO];

然后,我得到的url的值是,

file://localhost/Users/MY_ID/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/6AB76439-APP-ID-1C1BB92E/Library/test

iPhone模拟器和真正的iPhone都无法解析此url。

我认为问题出在这部分。

file://localhost

因为,没有那个部分,我可以从字符串中读取文件。

但是,我需要做的是通过NSURL获取"测试"文件。

由于[[MPMoviePlayerViewController alloc]initWithContentURL:]方法只能读取NSURL。

让我从本地文件系统中读取视频文件。

谢谢!!!

既然这在本地测试环境之外显然没有用处(因此无论如何都不能移植代码),为什么不在机器的根目录中创建一个"localhost"符号链接呢?

ln -s / /localhost

我甚至不知道MPMoviePlayerViewController可以用这种方式从本地文件系统读取文件。为了简单起见,为什么不把你的电影文件捆绑到应用程序中,或者把它放在dropbox之类的东西上呢?

最新更新