[TIMOB-28118] iOS: Add Ti.Geolocation.locationAccuracyAuthorization support on iOS 13 and older
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Low |
Status | Open |
Resolution | Unresolved |
Affected Version/s | Release 9.2.0 |
Fix Version/s | n/a |
Components | iOS |
Labels | geolocation, iOS, parity, permission |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2020-09-10T04:58:53.000+0000 |
Updated | 2021-02-22T19:00:45.000+0000 |
Description
*Summary:*
As of Titanium 9.2.0, we added a new [Ti.Geolocation.locationAccuracyAuthorization](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Geolocation-property-locationAccuracyAuthorization) property which is only supported on iOS 14. Attempting to use this property on older iOS versions causes an error to be logged and it will return an undocumented
-1
value. While this is by design, this makes the geolocation permission handling code more difficult to write between OS versions and platforms.
*Proposal:*
Add support for the "locationAccuracyAuthorization" on older iOS versions. It should work as following...
* On iOS 14 and higher, continue to read the native API.
* On older iOS version, return [ACCURACY_AUTHORIZATION_FULL](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Geolocation-property-ACCURACY_AUTHORIZATION_FULL) if location permission was granted. Otherwise return [ACCURACY_AUTHORIZATION_REDUCED](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Geolocation-property-ACCURACY_AUTHORIZATION_REDUCED).
*Current Solution:*
The below code is what people have to do "today" to access the precise GPS location data on iOS 14 and older... and Android. The extra iOS version check and Android guarding makes this more difficult to write.
function hasFullLocationAccuracy() {
if (OS_IOS && (OS_VERSION_MAJOR >= 14)) {
const accuracy = Ti.Geolocation.locationAccuracyAuthorization;
return (accuracy === Ti.Geolocation.ACCURACY_AUTHORIZATION_FULL);
}
return true
}
if (!Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE)) {
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, (e) => {
if (e.success) {
if (hasFullLocationAccuracy()) {
Ti.Geolocation.addEventListener('location', onLocationDataReceived);
} else {
alert('App was not granted "precise" location access.');
}
} else {
alert('Location permission was denied.');
}
});
} else if (!hasFullLocationAccuracy()) {
Ti.Geolocation.requestTemporaryFullAccuracyAuthorization('MyLocationPurposeKey', () => {
if (hasFullLocationAccuracy()) {
Ti.Geolocation.addEventListener('location', onLocationDataReceived);
} else {
alert('App was not granted "precise" location access.');
}
});
}
\\
*New Solution:*
If we do what this ticket suggests and add support on Android via ticket [TIMOB-28119], then we can reduce the above code to the below and it'll work on both Android and iOS.
if (!Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE)) {
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, (e) => {
if (e.success) {
if (Ti.Geolocation.locationAccuracyAuthorization === Ti.Geolocation.ACCURACY_AUTHORIZATION_FULL) {
Ti.Geolocation.addEventListener('location', onLocationDataReceived);
} else {
alert('App was not granted "precise" location access.');
}
} else {
alert('Location permission was denied.');
}
});
} else if (Ti.Geolocation.locationAccuracyAuthorization !== Ti.Geolocation.ACCURACY_AUTHORIZATION_FULL) {
Ti.Geolocation.requestTemporaryFullAccuracyAuthorization('MyLocationPurposeKey', () => {
if (Ti.Geolocation.locationAccuracyAuthorization === Ti.Geolocation.ACCURACY_AUTHORIZATION_FULL) {
Ti.Geolocation.addEventListener('location', onLocationDataReceived);
} else {
alert('App was not granted "precise" location access.');
}
});
}
_NOTE: The else-if part above is inconvenient too. Ideally, we should extend our existing hasLocationPermissions() and requestLocationPermissions() methods to avoid the requestTemporaryFullAccuracyAuthorization() method part under the else-if section._
No comments