要创建一个无需在platforms/ios/中工作即可工作的设置包,请在项目中创建一个本地插件。
./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
, and 创建一个新的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");
Edit从两个切换<source-file>
到一<resource-file>