[AC-6369] iOS: Ti.Geolocation.requestLocationPermissions doesn't fire given callback on 8.1.0+
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | n/a |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2019-12-30T09:20:04.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Titanium SDK & CLI |
| Labels | 8.1.0.GA, 8.1.1.GA, geolocation |
| Reporter | Andrea Vitale |
| Assignee | Motiur Rahman |
| Created | 2019-09-17T16:20:40.000+0000 |
| Updated | 2020-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.
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.
Hello [~Andrea.Vitale], Can you please follow up here on Vijay's comment? Let us know the status of your issue. Thanks.
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:
I've tried these below code in app/controllers/index.js file:<key>NSLocationWhenInUseUsageDescription</key> <string>Can we access your location when using the app</string> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <string>Can we use geolocation?</string>Environment details: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();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.2Guys I have this inside my tiapp.xml
and here is the permissions request function:<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>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.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'])); }); } }); }