Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-28118

iOS: Add Ti.Geolocation.locationAccuracyAuthorization support on iOS 13 and older

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Low
    • Resolution: Unresolved
    • Affects Version/s: Release 9.2.0
    • Fix Version/s: None
    • Component/s: iOS

      Description

      Summary:
      As of Titanium 9.2.0, we added a new Ti.Geolocation.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...

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jquick Joshua Quick
                Reporter:
                jquick Joshua Quick
              • Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Integration