[英]How to bundle text files into an xcode application to be readable at runtime?
I have added a few .js
files to an xcode
project:我在
xcode
项目中添加了一些.js
文件:
I am trying to load those .js
files at runtime but they apparently are not available.我正在尝试在运行时加载这些
.js
文件,但它们显然不可用。 This was seen by looking at the physical disk location of the simulator sandbox that we can find at: Bundle.main.bundlePath
whose value is:通过查看我们可以在以下位置找到的模拟器沙箱的物理磁盘位置可以看出这一点:
Bundle.main.bundlePath
,其值为:
/Users/steve/Library/Developer/CoreSimulator/Devices/CC7AE0CD-4EEE-412F-8E01-E5F55F73887E/data/Containers/Bundle/Application/ECB90596-FF9F-4E40-B500-0D55DDFC0E2E/hybrid.app
/Users/steve/Library/Developer/CoreSimulator/Devices/CC7AE0CD-4EEE-412F-8E01-E5F55F73887E/data/Containers/Bundle/Application/ECB90596-FF9F-4E40-B500-0D55DDFC0E2E/hybrid.app
Under that directory there are a few gyb
files, the Info.plist
, some code signature files, the storyboard
.. and one .js
file.在那个目录下有几个
gyb
文件, Info.plist
,一些代码签名文件, storyboard
.. 和一个.js
文件。 That one file was added to the project earlier and I am not certain using what mechanism.那个文件是早些时候添加到项目中的,我不确定使用什么机制。
I'd be happy to see all of the .js
files there - but maybe that's too much to ask?我很高兴在那里看到所有
.js
文件 - 但也许这要求太多了? Is there a different way to get those other .js
files - like reading from some Resources
bundle?有没有不同的方法来获取那些其他的
.js
文件——比如从一些Resources
包中读取?
Just drag any file into the Project navigator (project files structure browser) pane on the left.只需将任何文件拖到左侧的 Project navigator(项目文件结构浏览器)窗格中即可。 This file will be accessible via
该文件可通过以下方式访问
let jsonFilePath = Bundle.main.path(forResource: "fileName", ofType: "js")
This is an exercise in more deeply understanding xcode
project structures and Build phases
.这是一个更深入地了解
xcode
项目结构和Build phases
的练习。 Go to the Project Properties
then select the Build Phases
tab. Go 到
Project Properties
然后 select Build Phases
选项卡。 Select the Copy Bundle Resources
and add the files - javascript
in my case - in that section: Select
Copy Bundle Resources
并添加文件 - 在我的情况下为javascript
- 在该部分中:
The files now do show up in the root directory of the simulator output sandbox directory.这些文件现在确实显示在模拟器 output 沙箱目录的根目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.