transistorsoft / nativescript-background-geolocation-lt

Sophisticated, battery-conscious, cross-platform background-geolocation with motion-detection and geofencing
MIT License
73 stars 24 forks source link

null is not an object (evaluating 'app.keyWindow.rootViewController') #119

Closed bradseefeld closed 6 years ago

bradseefeld commented 6 years ago

Your Environment

Actual Behavior

Does not track. Instead the .ready call results in the .catch being triggered. The error is

null is not an object (evaluating 'app.keyWindow.rootViewController')
CONSOLE LOG file:///app/tns_modules/log4ts/build/appenders/ConsoleAppender.js:14:20: 2018-07-20 08:35:51 WARN [Tracker] - getAdapter@file:///app/tns_modules/nativescript-background-geolocation-lt/api.js:552:56
file:///app/tns_modules/nativescript-background-geolocation-lt/api.js:154:51
ZoneAwarePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:777:37
ready@file:///app/tns_modules/nativescript-background-geolocation-lt/api.js:145:27
init@file:///app/tracking/tracker.js:31:77
LocationService@file:///app/tracking/services/location.service.js:8:21
_createClass@file:///app/tns_modules/@angular/core/bundles/core.umd.js:10925:28
_createProviderInstance$1@file:///app/tns_modules/@angular/core/bundles/core.umd.js:10899:38
initNgModule@file:///app/tns_modules/@angular/core/bundles/core.umd.js:10852:53
NgModuleRef_@file:///app/tns_modules/@angular/core/bundles/core.umd.js:12107:21
createNgModuleRef@file:///app/tns_modules/@angular/core/bundles/core.umd.js:12096:28

Steps to Reproduce

  1. Use config above on iOS
  2. Run app in iOS emulator.

Context

Debug logs

I attempt to call getLogs in my catch, but this returns no log data.

bradseefeld commented 6 years ago

This happens if you call BackgroundGeolocation.ready() prior to init'ing your app component (in angular). This was easy for us to do since we were calling .ready in a constructor of something that was being injected into the app component. Strangely, this works fine on android, but fails on iOS. Delaying the .ready call fixes the issue.