Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

ZoneAwareError on with angular and iOS simulator #139

@abhayastudios

Description

@abhayastudios

I am using the plugin in a location.provider.ts whose saveUserLocation method (see code below) is called from my "home" page. Everything works find on Android and a real iOS device, however on the iOS simulator it most of the times gives me this error below and sometimes it just gives me the expected result (the location object).

{"line":994,"column":38,"sourceURL":"file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js","originalStack":"ZoneAwareError@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:994:38\nfile:///app/tns_modules/nativescript-geolocation/geolocation.js:160:41\ninvoke@file:///app/tns_modules/tns-core-modules/timer/timer.js:54:53\nonInvoke@file:///app/tns_modules/@angular/core/bundles/core.umd.js:4787:39\nrunGuarded@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:138:53\ntick@file:///app/tns_modules/tns-core-modules/timer/timer.js:19:26\nUIApplicationMain@[native code]\nstart@file:///app/tns_modules/tns-core-modules/application/application.js:258:26\nbootstrapApp@file:///app/tns_modules/nativescript-angular/platform-common.js:86:28\nbootstrapModule@file:///app/tns_modules/nativescript-angular/platform-common.js:72:26\nanonymous@file:///app/main.j

Any idea as to what may cause this? I don't care too much if this happens only on the simulator, I am a little worried it might also happen on a real device even though I have not seen it yet.

Thanks!

Which platform(s) does your issue occur on?

  • iOS simulator v10

Please, provide the following version numbers that your issue occurs with:

$ tns info
✔ Getting NativeScript components versions information...
⚠ Update available for component nativescript. Your current version is 4.1.0 and the latest available version is 4.1.1.
⚠ Update available for component tns-core-modules. Your current version is 3.4.1 and the latest available version is 4.1.0.
⚠ Update available for component tns-android. Your current version is 3.4.2 and the latest available version is 4.1.3.
⚠ Update available for component tns-ios. Your current version is 3.4.1 and the latest available version is 4.1.1.
{
  "description": "MyApp",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "com.abhayastudios.testapp",
    "tns-ios": {
      "version": "3.4.1"
    },
    "tns-android": {
      "version": "3.4.2"
    }
  },
  "dependencies": {
    "@angular/animations": "~5.2.0",
    "@angular/common": "~5.2.0",
    "@angular/compiler": "~5.2.0",
    "@angular/core": "~5.2.0",
    "@angular/forms": "~5.2.0",
    "@angular/http": "~5.2.0",
    "@angular/platform-browser": "~5.2.0",
    "@angular/platform-browser-dynamic": "~5.2.0",
    "@angular/router": "~5.2.0",
    "@teammaestro/nativescript-svg": "^1.0.1",
    "moment": "^2.18.1",
    "nativescript-angular": "~5.2.0",
    "nativescript-bitmap-factory": "^1.7.1",
    "nativescript-feedback": "^1.1.2",
    "nativescript-geolocation": "^4.2.6",
    "nativescript-gradient": "^2.0.1",
    "nativescript-image-swipe": "^2.1.0",
    "nativescript-imagepicker": "^5.0.0",
    "nativescript-iqkeyboardmanager": "^1.2.0",
    "nativescript-ngx-slides": "^1.0.0",
    "nativescript-platform-css": "^1.6.5",
    "nativescript-plugin-firebase": "^5.3.1",
    "nativescript-social-share": "^1.5.0",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-ui-listview": "^3.5.0",
    "nativescript-webview-interface": "^1.4.1",
    "reflect-metadata": "~0.1.8",
    "rxjs": "~5.5.2",
    "tns-core-modules": "~3.4.1",
    "zone.js": "^0.8.16"
  },
  "devDependencies": {
    "babel-traverse": "6.26.0",
    "babel-types": "6.26.0",
    "babylon": "6.18.0",
    "lazy": "1.0.11",
    "nativescript-dev-typescript": "~0.6.0",
    "typescript": "~2.6.2"
  }

Is there any code involved?

This the relevant part of my location.provider.ts:

/*
     First obtain permissions to use location services if needed, then try to obtain user's location
  */
  public saveUserLocation() {
    return new Promise((resolve, reject) => {

      geolocation.isEnabled().then((isEnabled:boolean) => {

        /* already have location permissions */

        if (isEnabled) {
          this.getCurrentLocation().then((location) => {
            resolve(location);
          }, (error) => {
            reject(error);
          });

        } else {

          /* first request location permissions */

          geolocation.enableLocationRequest().then(() => {

            /* granted location permissions, now get location */

            this.getCurrentLocation().then((location) => {
              resolve(location);
            }, (error) => {
              reject(error);
            });
          }, (error) => {
            console.error(`Failed to obtain location permissions: ${JSON.stringify(error)}`);
            reject(error);
          });
        }
      })
    });
  }

  /*
    Try to obtain user's location, assumes permissions are handled and save to user session if successful
    
    Returns promise containing location
  */
  private getCurrentLocation() {
    return new Promise((resolve, reject) => {
      geolocation.getCurrentLocation({
        desiredAccuracy: Accuracy.any,
        iosAllowsBackgroundLocationUpdates: false,
        maximumAge: 5000, // in milliseconds
        timeout: 5000, // in milliseconds
      })
      .then((location) => {
        resolve(location);
      }, (error) => {
        console.error(`Failed to obtain user location: ${JSON.stringify(error)}`);
        reject(error);
      });
    });
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions