如何在 XCode 中编辑 Phonegap/Cordova 项目?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29148835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to edit a Phonegap/Cordova-project in XCode?
提问by Dylan
I built a Phonegap/Cordova iOS-app using the command line. I can run it with the CLI.
我使用命令行构建了一个 Phonegap/Cordova iOS 应用程序。我可以使用 CLI 运行它。
After that I'm using XCode to compile and run the project that was created in 'platforms/ios
' on the iOS simulator. This works too.
之后,我使用 XCode 编译并运行platforms/ios
在 iOS 模拟器上的“ ”中创建的项目。这也有效。
Now I would like to use XCode to make changes to the app. XCode does display a www
-folder and config.xml
but these are the top ones in the project folder , not in platforms/ios
.
现在我想使用 XCode 对应用程序进行更改。XCode 确实显示了一个www
-folder,config.xml
但这些是项目文件夹中的顶部文件夹,而不是platforms/ios
.
So if I change the files that are displayed in XCode, no changes appear when I run the project.
因此,如果我更改 XCode 中显示的文件,则在运行项目时不会出现任何更改。
So, how can you edit a files of a Phonegap/Cordova project and run it with XCode ? (and still being able to use the CLI, would be nice as well).
那么,如何编辑 Phonegap/Cordova 项目的文件并使用 XCode 运行它?(并且仍然能够使用 CLI,也很好)。
回答by AtanuCSE
You always need to modify the project_folder/www
files. You can edit this files using Xcode, notepad++ or even with a simple notepad. Use what ever you like.
您总是需要修改project_folder/www
文件。您可以使用 Xcode、notepad++ 甚至是简单的记事本来编辑这些文件。使用你喜欢的任何东西。
Then run the command using CLI
然后使用 CLI 运行命令
cordova build ios
Your project is now completely built. You can see the changes you made inside platform/ios/.../www
files too. Now you can run the project using CLI or Xcode as wish. To run in CLI
您的项目现已完全构建。您也可以看到您在platform/ios/.../www
文件中所做的更改。现在您可以根据需要使用 CLI 或 Xcode 运行该项目。在 CLI 中运行
cordova run ios
Or to emulate in emulator
或者在模拟器中模拟
cordova emulate ios
回答by jcesarmobile
You are doing it right, you have to edit the root www folder.
Your problem is you have to do a cordova prepare ios
to copy the changes from the root www folder to the platform/ios/www
folder
你做得对,你必须编辑根 www 文件夹。您的问题是您必须cordova prepare ios
将更改从根 www 文件夹复制到该platform/ios/www
文件夹
You can do it from the cordova CLI or you can add a build script to you project (on build phases -> new Run Script phase) that runs the cordova prepare ios
every time you run the project from xcode
The code you need on the scrip is
您可以从cordova CLI 执行此操作,也可以将构建脚本添加到您的项目中(在构建阶段-> 新运行脚本阶段),cordova prepare ios
每次您从xcode 运行项目时都会运行该脚本您需要在脚本上的代码是
PATH=${PATH}:/usr/local/lib/node_modules/cordova/bin/:/usr/local/bin
cordova prepare ios
Put it the first one
把它放在第一个
If you really want to edit the patform/ios/www folder, on xcode you will see a staging folder, there you have the www folder and the changes you do there are applied to the project, but when you do a cordova prepare ios
that files will be replaced by the ones on the root www folder and you will lose all your work, so don't do that
如果你真的想编辑 patform/ios/www 文件夹,在 xcode 上你会看到一个 staging 文件夹,那里有 www 文件夹,你在那里所做的更改会应用于项目,但是当你这样做时cordova prepare ios
,文件将是替换为根 www 文件夹中的那些,您将丢失所有工作,所以不要这样做