NSURL fileURLWithPath:isDirectory:无法正常工作

时间:2012-02-16 11:06:19

标签: nsurl

我想做的只是从我的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都无法解析此网址。

我认为问题在于这一部分。

file://localhost

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

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

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

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

感谢!!!

1 个答案:

答案 0 :(得分:0)

由于这在本地测试环境之外显然没有用处(因此无论如何也不是可移植代码),为什么不在机器的根目录中创建“localhost”符号链接呢?

ln -s / /localhost

我甚至不知道MPMoviePlayerViewController可以通过这种方式从本地文件系统读取文件。为简单起见,为什么不将您的电影文件捆绑到应用程序中或将其托管在dropbox上?