简体   繁体   English

从主捆绑中获取目录的内容

[英]Get contents of directory from main bundle

I am including a directory full of files in my app. 我在我的应用程序中包含一个充满文件的目录。 I looked through the NSBundle docs, but I can't seem find out how to get the URL to this directory. 我浏览了NSBundle文档,但似乎找不到如何获取此目录的URL。 I'm trying to use the main bundle object. 我正在尝试使用主捆绑对象。

I have a directory "defaultImages" under a directory "Resources" in xCode. 我在xCode的目录“ Resources”下有一个目录“ defaultImages”。 I have confirmed that these are being copied to the device, how do I get the URL to them? 我已经确认将这些内容复制到设备上,如何获取它们的URL?

Specifically, the following does not work. 具体而言,以下操作无效。

[[NSBundle mainBundle]:URLForResource:@"defaultImages" withExtension:@"" subdirectory:@"Resources"]; 

尝试

 NSString *filepath = [[NSBundle mainBundle] pathForResource:@"defaultImages" ofType:@"footype"];

Apparently NSBundle will not locate a directory for you. 显然,NSBundle不会为您找到目录。 My solution was to put the contents of the directory inside a bundle, via How to make an iOS asset bundle? 我的解决方案是通过如何制作iOS资产捆绑包将目录的内容放入捆绑包中。 . I then added that bundle to my main application bundle. 然后,将该捆绑包添加到我的主应用程序捆绑包中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM