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>
在 运行 浏览器和我的安卓 phone 上使用 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>
感谢任何帮助。谢谢。
After running the code on browser and on my andriod phone using phonegap mobile developer
As documented,该插件仅支持原生 Android 和 iOS 环境,因此不适用于浏览器平台或 phonegap 开发者应用程序(已预编译)。
要使用此插件,您需要在本机移动平台上构建并运行应用程序:
cordova platform add android && cordova run android
cordova platform add ios && cordova run ios
刚刚在我的新项目上安装了 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>
在 运行 浏览器和我的安卓 phone 上使用 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>
感谢任何帮助。谢谢。
After running the code on browser and on my andriod phone using phonegap mobile developer
As documented,该插件仅支持原生 Android 和 iOS 环境,因此不适用于浏览器平台或 phonegap 开发者应用程序(已预编译)。
要使用此插件,您需要在本机移动平台上构建并运行应用程序:
cordova platform add android && cordova run android
cordova platform add ios && cordova run ios