![](/img/trans.png)
[英]Creating and using iOS settings.bundle values with JavaScript in PhoneGap
[英]Cordova Phonegap IOS App Settings.Bundle Possible?
所以我是移動開發的新手,但我接近使用HTML / CSS / JS和Cordova PhoneGap 3完成我的第一個IOS應用程序。我試圖允許用戶通過iPhone的原生“設置”應用程序提供文本輸入(灰色齒輪圖標)。 我的應用程序將在“設置”應用程序中擁有自己的設置部分,用戶可以在其中輸入特定的IP地址,然后我的應用程序將使用該地址。
到目前為止我發現的是我可能需要安裝PhoneGap插件並需要添加settings.bundle root.plist文件:
https://github.com/phonegap/phonegap-plugins/tree/DEPRECATED/iOS/ApplicationPreferences
Phonegap 3.0 iOS7 ApplicationPreferences插件
不幸的是,我沒有足夠的經驗來做到這一點:/我希望有經驗的有用獸醫可以更清楚地說出來並指出我正確的方向:
<script type="text/javascript" src="applicationPreferences.js"></script>
對不起所有漫長的新手混亂..我只是為了我的生活找不到一個易於理解的指南,如何在網上任何地方這樣做。 我相信在我之后會有很多有這些相同問題的人,所以我非常感謝你的幫助。 非常感謝。
要創建一個可以在平台/ 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
,然后創建一個新的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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.