【问题标题】:Cordova Phonegap IOS App Settings.Bundle Possible?Cordova Phonegap IOS App Settings.Bundle 可能吗?
【发布时间】:2014-04-26 00:48:23
【问题描述】:

所以我是移动开发的新手,但我即将使用 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 Plugin

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

不幸的是,我没有足够的经验来解决这个问题:/我希望有更多经验的有用兽医可以更清楚地说明它并为我指明正确的方向:

  • 我只是将 .h、.m 和 .js 文件分别放在“plugins”和“www”目录中,还是必须使用命令行“phonegap local plugin add htttps//github ...' 命令?
    • 命令行选项不起作用。这是因为 github 代码被弃用了吗?
  • 如何“在我的应用程序中引用插件”?它只是在我的 index.html 页面的正文中添加了这一额外的行还是还有更多内容?:<script type="text/javascript" src="applicationPreferences.js"></script>

对于所有冗长的新手困惑,我深表歉意。我一生都找不到关于如何在网上任何地方进行此操作的易于理解的指南。我相信在我之后会有很多人有同样的问题,所以我真的很感谢你的帮助。非常感谢。

【问题讨论】:

  • 我在github.com/apla/me.apla.cordova.app-preferences 上工作得很好,但是如果不打开 xcode 项目(一个非启动器,因为平台 / 在 gitignore 中),就无法添加 Settings.bundle。完成后我会发布答案。

标签: javascript ios iphone cordova settings.bundle


【解决方案1】:

要创建一个无需在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/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");

编辑从两个&lt;source-file&gt;s 切换到一个&lt;resource-file&gt;

【讨论】:

  • 嗨,这个在 2019 年有效还是官方插件出来了?
  • me.apla.cordova.app-preferences 插件似乎已被废弃,不再与最新版本的 Cordova 兼容。是否有从 iOS 的“设置”应用访问设置的新方法?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
  • 2013-01-10
相关资源
最近更新 更多