Cordova Phonegap IOS App Settings.Bundle可能吗?

pro*_*rer 8 javascript iphone ios settings.bundle cordova

所以我是移动开发的新手,但我接近使用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插件

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>

对不起所有漫长的新手混乱..我只是为了我的生活找不到一个易于理解的指南,如何在网上任何地方这样做.我相信在我之后会有很多有这些相同问题的人,所以我非常感谢你的帮助.非常感谢.

Dav*_*her 10

要创建一个可以在平台/ 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>
Run Code Online (Sandbox Code Playgroud)

在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>
Run Code Online (Sandbox Code Playgroud)

在项目的根目录下运行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");
Run Code Online (Sandbox Code Playgroud)

编辑从两个<source-file>s 切换到一个<resource-file>

  • 嗨,这在2019年有效吗,还是为此推出了官方插件? (2认同)