Cordova 诊断插件不工作
Cordova diagnostic plugin not working
我正在使用诊断插件来获取有关该位置是否已打开的信息。该插件工作正常,直到我由于代码中的一些问题将其删除。
现在当我在同一个应用程序中再次添加插件时,它不起作用。
同一个插件在我为演示目的而创建的另一个应用程序中工作。
我也试过诊断插件的旧版本。
function checkLocationEnabled(){
cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
alert("Location is " + (enabled ? "enabled" : "disabled"));
alert(enabled);
if(enabled == false){
cordova.plugins.locationAccuracy.canRequest(function(canRequest){
if(canRequest){
cordova.plugins.locationAccuracy.request(function(){
alert("GPS turned on");
setLatitudeLongitude();
}, function (error){
alert("Request failed");
if(error){
// Android only
alert("error code="+error.code+"; error message="+error.message);
if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED){
if(window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")){
cordova.plugins.diagnostic.switchToLocationSettings();
}
}
}
}, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY // iOS will ignore this
);
}
});
} else if (enabled == true){
setLatitudeLongitude();
}
}, function(error){
alert("The following error occurred: "+error);
});
}
我的 config.xml 文件中的条目
<plugin name="cordova.plugins.diagnostic" spec="~3.6.5" />
科尔多瓦版本:6.5.0
已安装的平台:
android6.2.3
浏览器 4.1.0
ios4.3.1
<preference name="android-minSdkVersion" value="14" />
尝试在 chrome 上调试,它显示未定义的错误 'cannot read property diagnostic'。
我也在使用 Windows 7,我已经在 android 5、5.1、6.0 的不同版本上测试了相同的应用程序。 (三星+索尼)
它曾经工作过并显示 'Location is enabled/disabled' 的警报。
it shows the error 'cannot read property isLocationEnabled' of undefined.
这表示 cordova.plugins.diagnostic
对象不可用。
这最常见的原因是在 deviceready
事件触发之前尝试调用插件,因为 Cordova 在运行时动态加载插件的 JS 组件。
另一个可能的原因是插件没有正确安装到项目中 - 如果 diagnostic.js
列在源代码中,请检查 Chrome 开发工具。如果不存在,请执行 cordova platform rm android && cordova platform add android
重建本机 Android 项目。
我正在使用诊断插件来获取有关该位置是否已打开的信息。该插件工作正常,直到我由于代码中的一些问题将其删除。
现在当我在同一个应用程序中再次添加插件时,它不起作用。
同一个插件在我为演示目的而创建的另一个应用程序中工作。
我也试过诊断插件的旧版本。
function checkLocationEnabled(){
cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
alert("Location is " + (enabled ? "enabled" : "disabled"));
alert(enabled);
if(enabled == false){
cordova.plugins.locationAccuracy.canRequest(function(canRequest){
if(canRequest){
cordova.plugins.locationAccuracy.request(function(){
alert("GPS turned on");
setLatitudeLongitude();
}, function (error){
alert("Request failed");
if(error){
// Android only
alert("error code="+error.code+"; error message="+error.message);
if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED){
if(window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")){
cordova.plugins.diagnostic.switchToLocationSettings();
}
}
}
}, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY // iOS will ignore this
);
}
});
} else if (enabled == true){
setLatitudeLongitude();
}
}, function(error){
alert("The following error occurred: "+error);
});
}
我的 config.xml 文件中的条目
<plugin name="cordova.plugins.diagnostic" spec="~3.6.5" />
科尔多瓦版本:6.5.0
已安装的平台: android6.2.3 浏览器 4.1.0 ios4.3.1
<preference name="android-minSdkVersion" value="14" />
尝试在 chrome 上调试,它显示未定义的错误 'cannot read property diagnostic'。
我也在使用 Windows 7,我已经在 android 5、5.1、6.0 的不同版本上测试了相同的应用程序。 (三星+索尼)
它曾经工作过并显示 'Location is enabled/disabled' 的警报。
it shows the error 'cannot read property isLocationEnabled' of undefined.
这表示 cordova.plugins.diagnostic
对象不可用。
这最常见的原因是在 deviceready
事件触发之前尝试调用插件,因为 Cordova 在运行时动态加载插件的 JS 组件。
另一个可能的原因是插件没有正确安装到项目中 - 如果 diagnostic.js
列在源代码中,请检查 Chrome 开发工具。如果不存在,请执行 cordova platform rm android && cordova platform add android
重建本机 Android 项目。