Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23655] Windows: Implement Ti.Geolocation.requestLocationPermissions/hasLocationPermissions methods to match iOS and Android behaviour

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-10-11T12:42:21.000+0000
Affected Version/sRelease 5.4.0
Fix Version/sRelease 6.0.0
ComponentsWindows
Labelsparity, qe-5.4.0
ReporterEwan Harris
AssigneeKota Iguchi
Created2016-07-19T17:41:41.000+0000
Updated2016-10-13T14:17:17.000+0000

Description

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

Attachments

FileDateSize
request.png2016-07-27T12:43:42.000+000028053

Comments

  1. Gary Mathews 2016-07-26

    master: https://github.com/appcelerator/titanium_mobile_windows/pull/789
  2. Ewan Harris 2016-10-05

    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 issue
  3. Kota Iguchi 2016-10-11

    I was able to reproduce it. I saw callback is fired twice (before & after the prompt) and then crashed. Started looking into it.
  4. Kota Iguchi 2016-10-11

    6_0_X: https://github.com/appcelerator/titanium_mobile_windows/pull/878 master: https://github.com/appcelerator/titanium_mobile_windows/pull/879
  5. Ewan Harris 2016-10-13

    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

JSON Source