簡體   English   中英

cordova.plugins.diagnostic 不適用於新創建的應用程序

[英]cordova.plugins.diagnostic not working on newly created App

剛剛在我的新項目上安裝了 cordova 插件。 cordova plugin add cordova.plugins.diagnostic我成功添加了。

然后我首先使用以下基本代碼對其進行測試:

<script type="text/javascript" src="cordova.js"></script>

<script type="text/javascript">
        function log(msg) {
            console.log(msg);
            document.body.innerHTML += '<p>' + msg + '</p><br><br><br><br>';
        }

        function onReady() {
            log("deviceready");
            try {
                cordova.plugins.diagnostic.isLocationEnabled(function(enabled) {
                    log("Location enabled: " + enabled);
                }, function(error) {
                    log("A plugin error occurred: " + error);
                });
            } catch (e) {
                log("An exception occurred: " + e.message);
            }
        }
        document.addEventListener("deviceready", onReady, false);
    </script>

使用 phonegap 移動開發人員在瀏覽器和我的安卓手機上運行代碼后。 我有一個錯誤。 An exception occurred: Cannot read property 'diagnostic' of undefined 我嘗試構建應用程序的apk,同樣是錯誤。 可能是什么問題呢?

這是我的插件列表: cordova-plugin-dialogs 2.0.2 "Notification" cordova-plugin-geolocation 4.0.2 "Geolocation" cordova-plugin-inappbrowser 3.2.0 "InAppBrowser" cordova-plugin-network-information 2.0.2 "Network Information" cordova-plugin-request-location-accuracy 2.3.0 "Request Location Accuracy" cordova-plugin-whitelist 1.3.4 "Whitelist" cordova.plugins.diagnostic 5.0.1 "Diagnostic"

還有我的 config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.test.location" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Test</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <preference name="phonegap-version" value="cli-6.4.0" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <plugin name="cordova-plugin-dialogs" spec="~2.0.2" />
    <plugin name="cordova-plugin-geolocation" spec="~4.0.2" />
    <plugin name="cordova-plugin-request-location-accuracy" spec="~2.3.0" />
    <plugin name="cordova-plugin-inappbrowser" spec="~3.2.0" />
    <plugin name="cordova-plugin-network-information" spec="~2.0.2" />
    <plugin name="cordova.plugins.diagnostic"/>
</widget>

任何幫助表示贊賞。 謝謝你。

使用 phonegap 移動開發人員在瀏覽器和我的安卓手機上運行代碼后

如文件所述,該插件僅支持本機 Android 和 iOS 環境,因此不適用於瀏覽器平台或 phonegap 開發人員應用程序(預編譯)。

要使用此插件,您需要在本機移動平台上構建和運行該應用程序:

cordova platform add android && cordova run android
cordova platform add ios && cordova run ios

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM