Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6369] iOS: Ti.Geolocation.requestLocationPermissions doesn't fire given callback on 8.1.0+

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2019-12-30T09:20:04.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labels8.1.0.GA, 8.1.1.GA, geolocation
ReporterAndrea Vitale
AssigneeMotiur Rahman
Created2019-09-17T16:20:40.000+0000
Updated2020-01-14T18:10:04.000+0000

Description

When using
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, event => Ti.API.info(event))
the given callback is never fired on Ti SDK 8.1.0.GA and 8.1.1.GA. The same code on Ti SDK 8.0.0.GA works as expected.

Comments

  1. Vijay Singh 2019-09-26

    It's working fine for me with 8.1.0.GA. Is there any particular iOS version? I assume you have added key "NSLocationWhenInUseUsageDescription" in tiapp.xml.
  2. Sharif AbuDarda 2019-10-19

    Hello [~Andrea.Vitale], Can you please follow up here on Vijay's comment? Let us know the status of your issue. Thanks.
  3. Riduanul Islam 2019-12-27

    Hi [~Andrea.Vitale], We have tested this issue in real device and failed to reproduce this issue. Ti.Geolocation.requestLocationPermissions has fired and returned the callback function. Make sure in your tiapp.xml ios / plist / dict section you have added these below:
       <key>NSLocationWhenInUseUsageDescription</key>
       <string>Can we access your location when using the app</string>
       <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
        <string>Can we use geolocation?</string>
       
    I've tried these below code in app/controllers/index.js file:
       function doClick(e) {
       
       	var hasLocationPermission = Ti.Geolocation
       			.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE);
       	if (!hasLocationPermission) {
       		Ti.Geolocation.requestLocationPermissions(
       				Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, function(e) {
       					if (e.success) {
       						getLocation();
       						// permission granted
       					} else {
       						// permission refused
       					}
       				});
       	}else{
       		getLocation();
       	}
       
       	function getLocation(e) {
       		Titanium.Geolocation.preferredProvider = "gps";
       		Titanium.Geolocation.purpose = "user coordinates";
       		Titanium.Geolocation.distanceFilter = 10;
       
       		Titanium.Geolocation.getCurrentPosition(function(e) {
       			if (!e.success || e.error) {
       				return;
       			}
       
       			var longitude = e.coords.longitude;
       			var latitude = e.coords.latitude;
       			var altitude = e.coords.altitude;
       			var heading = e.coords.heading;
       			var accuracy = e.coords.accuracy;
       			var speed = e.coords.speed;
       			var timestamp = e.coords.timestamp;
       			var altitudeAccuracy = e.coords.altitudeAccuracy;
       			Titanium.Geolocation.reverseGeocoder(latitude, longitude, function(
       					evt) {
       				if (evt.success) {
       					var places = evt.places;
       					alert('Your Current Location is  : ' + places[0].address
       							+ '\n Latitude:' + latitude + '\nLongitude : '
       							+ longitude);
       
       				} else {
       					Ti.API.info("Reverse geocoding error");
       				}
       			});
       		});
       	}
       }
       
       $.index.open();
       
    Environment details:
       Operating System
         Name                        = Mac OS X
         Version                     = 10.14.6
         Architecture                = 64bit
         # CPUs                      = 4
         Memory                      = 8589934592
       
       Node.js
         Node.js Version             = 8.9.4
         npm Version                 = 6.5.0
       
       Titanium CLI
         CLI Version                 = 5.2.2
       
       Titanium SDK
         SDK Version                 = 8.3.0.GA
         Target Platform             = iphone 5S
       [INFO]  Building using iOS SDK: 13.2
       
  4. Andrea Vitale 2020-01-14

    Guys I have this inside my tiapp.xml
               <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
               <string>Per proporti sempre la combinazione migliore tra prodotti e farmacie e per mostrarti le migliori offerte vicine a te, abbiamo bisogno di accedere alla tua posizione!</string>
               <key>NSLocationWhenInUseUsageDescription</key>
               <string>Per proporti sempre la combinazione migliore tra prodotti e farmacie e per mostrarti le migliori offerte vicine a te, abbiamo bisogno di accedere alla tua posizione!</string>
       
    and here is the permissions request function:
           const defaultRequestOptions = {
               mode: AuthorizationTypes.IN_USE
           };
       
           const requestLocationPermissions = function(options = {}) {
               options = _.defaults(options, defaultRequestOptions);
       
               return new Promise((resolve, reject) => {
                   if (Ti.Geolocation.hasLocationPermissions(options.mode)) {
                       resolve();
                   } else {
                       Ti.Geolocation.requestLocationPermissions(options.mode, event => {
                           Ti.API.info('Got response:', event);
       
                               event.success
                                   ? resolve()
                                   : reject(_.pick(event, ['error', 'code']));
                       });
                   }
               });
           }
       
    This is in a REAL app and sometimes works and sometimes it doesn't. Log message "Got response..." isn't printed out and the promise isn't resolved or rejected.

JSON Source