要创建一个无需在平台/ ios /中解决问题即可工作的Settings包,请在您的项目中创建一个本地插件。
./src/ios/plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
id="com.example.application.settings"
version="0.4.2">
<name>Application Settings</name>
<description>My Application's Default Settings</description>
<license>Proprietary</license>
<keywords>preferences, settings, default</keywords>
<repo>https://github.com/</repo>
<platform name="ios">
<resource-file src="Settings.bundle" />
</platform>
</plugin>
在Xcode中,打开./src/ios
和create a new Settings.bundle
./src/ios/Settings.bundle/Root.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Title</key>
<string>API Server</string>
<key>Type</key>
<string>PSGroupSpecifier</string>
</dict>
<dict>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
<key>DefaultValue</key>
<string>https://api.example.com</string>
<key>IsSecure</key>
<false/>
<key>Key</key>
<string>name_preference</string>
<key>KeyboardType</key>
<string>Alphabet</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
</array>
<key>StringsTable</key>
<string>Root</string>
</dict>
</plist>
在项目的根目录下,运行cordova plugin add ./src/ios
。它会说Installing "com.dataonline.dolores.settings" for ios
。
使用me.apla.cordova.app-preferences从Javascript加载这些设置。
./src/client/preferences。JS
function ApplicationPreferences(){
var _this = this;
this.server = window.location.origin;
document.addEventListener('deviceready', function(){
function loaded(server){_this.server = server;}
plugins.appPreferences.fetch(loaded, function(){}, 'api_server');
});
};
applicationPreferences = new ApplicationPreferences();
// Later..
$.get(applicationPreferences.server + "/api/data");
编辑从两个<source-file>
小号切换到一个<resource-file>
我已经得到这方面的工作非常好,https://github.com/apla/me.apla.cordova.app-但无法打开xcode项目(非启动器,因为平台/位于gitignore中)而无法添加Settings.bundle。一旦完成,我会发布一个答案。 –