2014-03-19 92 views
7

所以我是新来的移动开发,但我接近完成我的第一个IOS应用程序使用HTML/CSS/JS和科尔多瓦PhoneGap 3.我试图让用户提供通过iPhone本机“文本输入设置“应用程序(灰色齿轮图标)。我的应用程序将在“设置”应用程序中拥有自己的设置部分,用户可以在其中输入特定的IP地址,然后我的应用程序将使用该部分。科尔多瓦电话IOS应用程序Settings.Bundle可能吗?

我已经发现了迄今为止的是,我可能需要安装一个插件的PhoneGap和需要添加settings.bundle root.plist文件:

https://github.com/phonegap/phonegap-plugins/tree/DEPRECATED/iOS/ApplicationPreferences

Phonegap 3.0 iOS7 ApplicationPreferences Plugin

https://developer.apple.com/library/ios/DOCUMENTATION/Cocoa/Conceptual/UserDefaults/Preferences/Preferences.html

不幸的是,我没有足够的经验足以使这个:/我希望有更多经验的有益的兽医可以拼出更清楚一点,并指出我在右边方向:

  • 难道我只是拿.H,.M,和.js文件,并把他们在“插件”和“WWW”目录恭敬,或做我必须使用命令行“的PhoneGap本地插件添加htttps // github ...'命令?
    • 命令行选项不起作用。这是因为github代码已被弃用?
  • 如何“引用我的应用程序中的插件”?是它只是加入这个额外的行到我的index.html页面的身体还是有更给它?:<script type="text/javascript" src="applicationPreferences.js"></script>

对不起,所有的冗长的新秀混乱..我只是为我的生命无法找到一个简单的了解如何在网上任何地方做到这一点的指南。我相信在我之后会有很多这些相同的问题,所以我非常感谢帮助。非常感谢。

+0

我已经得到这方面的工作非常好,https://github.com/apla/me.apla.cordova.app-但无法打开xcode项目(非启动器,因为平台/位于gitignore中)而无法添加Settings.bundle。一旦完成,我会发布一个答案。 –

回答

9

要创建一个无需在平台/ 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/ioscreate 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>

相关问题