Description
As part of TIMOB-19479 the Gelocation permissions was rewritten to be consistent across iOS and Android and use Ti.Geolocation.hasPermissions. Windows currently uses a different way to request permissions that can be seen in TIMOB-23389, however it should move to match iOS and Android. A code sample can be found below and a real world example found [in Geocoder](
https://github.com/appcelerator-developer-relations/appc-sample-geocoder/blob/stable/app/lib/permissions.js#L59)
Ti.Geolocation.preferredProvider = "gps";
function locationCallback(e) {
if (!e.success || e.error) {
alert("error:" + JSON.stringify(e.error));
return;
}
Ti.API.info(JSON.stringify(e));
var longitude = e.coords.longitude;
var latitude = e.coords.latitude;
};
if (Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS)) {
alert("Access already granted!");
Titanium.Geolocation.addEventListener("location", locationCallback);
} else {
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function(e) {
if (e.success === true) {
alert("Access now granted!");
Titanium.Geolocation.addEventListener("location", locationCallback);
} else {
console.log("Access denied, error: " + e.error);
}
});
}
Additionally to this Ti.Geolocation.hasLocationPermissions should also be implemented to allow a user to check if permissions have already been granted
Steps to reproduce
Run the code above on Windows Platform appc run -p windows
Actual result
You should be prompted to allow location
Expected result
The app will throw an error as the methods are not implemented
master: https://github.com/appcelerator/titanium_mobile_windows/pull/789
Reopening ticket: OS: Microsoft Windows 10 Pro 10.0.14393 Appc core: 6.0.0-56 Appc NPM: 4.2.8-7 Ti SDK: 6.0.0.v20161004202820 Appc Studio: 4.8.0.201609292239 Lumia 550 10.0 When I'm using the code in the description I get the following * On first launch I am prompted to allow the app to access my location. It looks like my callback that is passed to
requestLocationPermissions
is called immediately rather than when I allow/reject access as I would expect. When I click yes or no on the prompt my app then crashes * On subsequent launches my app crashes on launch I see similar behavior when using the example in the PR. I have tried manually adding the location capability myself but this does not fix the issueI was able to reproduce it. I saw callback is fired twice (before & after the prompt) and then crashed. Started looking into it.
6_0_X: https://github.com/appcelerator/titanium_mobile_windows/pull/878 master: https://github.com/appcelerator/titanium_mobile_windows/pull/879
Verified using: OS: Microsoft Windows 10 Pro 10.0.14393 Appc core: 6.0.0-58 Appc NPM: 4.2.8-7 Ti SDK: 6.0.0.v20161012201942 Appc Studio: 4.8.0.201610060953 Lumia 550 10.0 Both pieces of example code now work as expected and [geocoder](https://github.com/appcelerator-developer-relations/appc-sample-geocoder) also works as expected Closing ticket