Closed abhishekthakur1995 closed 7 years ago
Please given more details, such as OS version (e.g. iOS 11), platform version (e.g. cordova-ios@4.3.1) and plugin version (e.g. cordova-plugin-request-location-accuracy@2.2.2)
ios-platform-version : 4.3.1 cordova-plugin-request-location-accuracy@2.2.2 ios version : 10.12.6
I've re-tested the scenario you describe using the example project and the plugin appears to behave as expected - see this screencapture.
Please try to build and run the example project yourself and see if you can replicate the issue in order to eliminate the possibility of a bug in your implementation
`CommonFactory.enableLocation = function(successCallBack) {
cordova.plugins.locationAccuracy.canRequest(function(canRequest){
if(canRequest){
console.log(canRequest);
cordova.plugins.locationAccuracy.request(function(){
successCallBack();
}, function (error){
if(error){
if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED){
cordova.plugins.diagnostic.switchToLocationSettings();
}
}
}, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY // iOS will ignore this
);
}
});
}`
can you check if the code is correct...it would be very helpful.
The code looks correct. Check that the app has location permission when this is called. Also note the iOS caveat regarding pressing of the "Cancel" button.
I am disabling the location on start as you showed in the screencapture .... so i don't think if it would have location permission when the request() is called.
This plugin is designed to be used in conjunction with cordova-diagnostic-plugin, so you should do something like:
function onError(error){
console.error("The following error occurred: "+error);
}
function handleLocationAuthorizationStatus(cb, status){
switch(status){
case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
requestLocationAuthorization(cb);
break;
case cordova.plugins.diagnostic.permissionStatus.DENIED:
cb(false);
break;
case cordova.plugins.diagnostic.permissionStatus.GRANTED:
cb(true);
break;
case cordova.plugins.diagnostic.permissionStatus.GRANTED_WHEN_IN_USE:
cb(true);
break;
}
}
function requestLocationAuthorization(cb){
cordova.plugins.diagnostic.requestLocationAuthorization(handleLocationAuthorizationStatus.bind(this, cb), onError);
}
function ensureLocationAuthorization(cb){
cordova.plugins.diagnostic.getLocationAuthorizationStatus(handleLocationAuthorizationStatus.bind(this, cb), onError);
}
CommonFactory.enableLocation = function(successCallBack) {
ensureLocationAuthorization(function(isAuthorized){
if(isAuthorized){
cordova.plugins.locationAccuracy.canRequest(function(canRequest){
if(canRequest){
console.log(canRequest);
cordova.plugins.locationAccuracy.request(function(){
successCallBack();
}, function (error){
if(error){
if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED){
cordova.plugins.diagnostic.switchToLocationSettings();
}
}
}, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY // iOS will ignore this
);
}
});
}else{
onError("Permission denied");
}
});
}
I have turned off the location and when cordova.plugins.locationAccuracy.request(successCB, errorCB) executes nothing happens and the control goes to its success callback. Native Settings does not open. Working excellent in android though.