cordova-plugin-ibeacon
cordova-plugin-ibeacon copied to clipboard
IOS - Domain=kCLErrorDomain Code=4, even with WhenInUseAuthorization
Hi, the plugin works fine on Android, but I get some issues with IOS (9.3 and above) and Ionic-Cordova. The code is like this:
cordova.plugins.locationManager.requestAlwaysAuthorization();
var delegate = new cordova.plugins.locationManager.Delegate();
delegate.didEnterRegion = function (result){ // Some code };
cordova.plugins.locationManager.setDelegate(delegate);
var _beaconR = new cordova.plugins.locationManager.BeaconRegion(beacon.id, beacon.uuid);
cordova.plugins.locationManager.startMonitoringForRegion(_beaconR) .fail(function(e) { console.error(e); }).done();
I put all the authorization descriptions in info .plist:
NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
NSLocationAlwaysUsageDescription
Still, I get this error:
_onDelegateCallback() {"eventType":"monitoringDidFailForRegionWithError","error":"Error Domain=kCLErrorDomain Code=4 \"(null)\"","region":"11111111"
Is it a plugin issue, or am I missing something? Thankyou. Carlo
I could make it work, but with a too stricted condition. Only if I ask for permission at the very start of the App (the first instruction in ionicPlatform.ready:
$ionicPlatform.ready(function() {
cordova.plugins.locationManager.requestAlwaysAuthorization();
[...]
});
Only this way I get the App to ask for permission and then work properly.
It's not a good behaviour for me because not always I want to ask for permission (some users of the App will not need to use the Beacon).
But I cannot find a better solution. If I ask for permission later, only when I enter a specific page, I get the error monitoringDidFailForRegionWithError
because, don't know why, the plugin already decided that the user didn't answer to the authorization request (AuthorizationStatusNotDetermined), so the state is already "Denied".
Anyone had a similar issue and knows a better solution?
Thankyou.
Carlo