设备未在Cordova中启动

设备未在Cordova中启动

本文介绍了设备未在Cordova中启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的cordova项目的deviceready不能正确启动(至少在iOS中).我已经搜索了几个小时,但仍然无法解决.我做错了什么吗? js/cordova.js的路径也存在:

The deviceready isn't firing correctly (at least in iOS) for my cordova project. I have searched for hours and still cannot figure this out. Am I doing something incorrectly? The path to js/cordova.js exists as well:

<html>
<head>
    <title>Geolocation</title>
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi, user-scalable=no" />
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="css/app.css">
    <script type="text/javascript">

    // Fastclick
    if ('addEventListener' in document) {
        document.addEventListener('DOMContentLoaded', function() {
        FastClick.attach(document.body);
        }, false);
    }

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

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

    // device APIs are available
    //
    function onDeviceReady() {
        alert("ready");
        // Now safe to use device APIs
    }

    </script>
</head>
<body onload="onLoad()">

我不确定要丢失什么,因为如果在Chrome中进行检查,不会出现任何错误

I'm not sure what I'm missing as I'm not getting any errors if I inspect in Chrome

推荐答案

更新

因此,通过从正文中删除onload ="onLoad()"并替换为以下内容,我可以"deviceready"工作:

So I got "deviceready" to work by removing the onload="onLoad()" from the body and replacing this:

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

仅此而已:

document.addEventListener("deviceready", onDeviceReady, false);

这篇关于设备未在Cordova中启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:05