插件无法在onDeviceReady for iOS

时间:2015-12-30 15:26:37

标签: cordova phonegap-plugins cordova-plugins

我通过此tutorial创建了一个cordova项目。

它可以工作,但是当我尝试安装插件时(使用教程中的指定方法),它不会启用插件的JS api。

示例:我安装了cordova-plugin-device,当应用程序通过Xcode运行时,JS中的window.device没有做任何事情。

以下是包含所有代码的应用HTML:

<html>
  <head>
    <title>Homeschool Mapper</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        var element = document.getElementById('deviceProperties');
        element.innerHTML = 'Device Model: '    + device.model    + '<br />' +
                            'Device Cordova: '  + device.cordova  + '<br />' +
                            'Device Platform: ' + device.platform + '<br />' +
                            'Device UUID: '     + device.uuid     + '<br />' +
                            'Device Version: '  + device.version  + '<br />';
    }

    </script>
  </head>
  <body>
    <p id="deviceProperties">Loading device properties...</p>
  </body>
</html>

这些是我在创建项目时所做的命令:

cordova-ios/bin/create app com.swordhiltstudios.homeschoolmapper Homeschool\ Mapper
cd app
plugman install --platform ios --project . --plugin cordova-plugin-dialogs
plugman install --platform ios --project . --plugin cordova-plugin-device
plugman install --platform ios --project . --plugin cordova-plugin-local-notifications

在这些命令之后,我设置了storyboard in Xcode

Xcode输出

2015-12-30 10:00:53.440 Homeschool Mapper[1229:501233] Apache Cordova native platform version 4.0.1 is starting. 2015-12-30
     

10:00:53.444 Homeschool Mapper [1229:501233]多任务 - &gt;设备:   是的,应用程序:是2015-12-30 10:00:53.509 Homeschool Mapper [1229:501233]   Apache Cordova本机平台版本4.0.1正在启动。 2015年12月30日   10:00:53.510 Homeschool Mapper [1229:501233]多任务 - &gt;设备:   是的,应用程序:是2015-12-30 10:00:53.523 Homeschool Mapper [1229:501233]

Started backup to iCloud! Please be careful. Your application might be rejected by Apple if you store too much data. For more
     

信息请阅读“iOS数据存储指南”:   https://developer.apple.com/icloud/documentation/data-storage/至   禁用Web存储备份到iCloud,设置BackupWebStorage   在Cordova config.xml文件中优先选择“local”

2015-12-30 10:00:53.850 Homeschool Mapper[1229:501233] Using UIWebView 2015-12-30 10:00:53.861 Homeschool Mapper[1229:501233]
     

[CDVTimer] [handleopenurl] 0.887990ms 2015-12-30 10:00:53.874   Homeschool Mapper [1229:501233] [CDVTimer] [intentandnavigationfilter]       11.270046ms 2015-12-30 10:00:53.877 Homeschool Mapper [1229:501233] [CDVTimer] [gesturehandler] 0.805974ms 2015-12-30 10:00:53.881   Homeschool Mapper [1229:501233] [CDVTimer] [localnotification]       3.884017ms 2015-12-30 10:00:53.882 Homeschool Mapper [1229:501233] [CDVTimer] [localnotification] 0.041008ms 2015-12-30 10:00:53.883   Homeschool Mapper [1229:501233] [CDVTimer] [TotalPluginStartup]       23.401022ms 2015-12-30 10:00:55.530 Homeschool Mapper [1229:501233]由于页面加载而重置插件。 2015-12-30 10:00:55.895 Homeschool   Mapper [1229:501233]成品装载:   文件:///var/mobile/Containers/Bundle/Application/4FB0A5E5-9CB0-49CD-9113-310A665B0C80/Homeschool%20Mapper.app/www/index.html

更新

当我没有将设备插件放在onDeviceReady中时,只需执行以下操作即可;所以这似乎是一个与插件直接相关的问题,而不是Cordova本身:

function onDeviceReady() {
    var element = document.getElementById('deviceProperties');
    element.innerHTML = JSON.stringify(['hello']);
}

0 个答案:

没有答案