【发布时间】:2017-07-13 05:38:45
【问题描述】:
我正在使用诊断插件来获取有关位置是否打开的信息。由于代码中的一些问题,该插件工作正常,直到我将其删除。
现在,当我在同一个应用程序中再次添加插件时,它无法正常工作。
相同的插件在我为演示目的创建的另一个应用程序中工作。
我也尝试过旧版诊断插件。
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" />
Cordova 版本:6.5.0
已安装平台: 安卓 6.2.3 浏览器 4.1.0 ios 4.3.1
<preference name="android-minSdkVersion" value="14" />
尝试在 chrome 上调试,它显示错误“无法读取未定义的属性诊断”。
此外,我使用的是 Windows 7,并且在不同版本的 android 5、5.1、6.0 上测试了相同的应用程序。 (三星+索尼)
它以前可以工作并显示“位置已启用/已禁用”的警报。
【问题讨论】:
-
您需要比“它不起作用”更具体。描述预期与实际行为。提供您的测试环境的详细信息,例如运行 Android 7.1.1 的设备。如果有 JS 或原生的错误信息产生,请贴出来:尝试连接 Chrome Dev Tools 到 Webview 来查看 JS 错误并在代码中放置断点来逐步调试。
-
@DaveAlden 做到了
标签: android cordova phonegap-plugins phonegap