I have a problem, I know because of how javascript works, but I do not know how to work around it.
I'm using Cordova and a feature needs to use Phone permission on Android.
So before running the method I check if the permission was granted, if I do not ask permission.
The problem is that you do not expect the return and the value always stays undefined.
Follow the code
var getImeiNumeber = function()
{
if (hasReadPermission() !== true){
requestReadPermission();
getImeiNumeber();
} else if (hasReadPermission() === false) {
window.plugins.sim.getSimInfo(successCallback, errorCallback);
}
}
The function
var successCallback = function(result)
{
console.log(result);
return result;
}
var errorCallback = function(error)
{
console.log(error);
}
// Android only: check permission
var hasReadPermission = function()
{
window.plugins.sim.hasReadPermission(successCallback, errorCallback);
}
// Android only: request permission
var requestReadPermission = function()
{
window.plugins.sim.requestReadPermission(successCallback, errorCallback);
}