dpa99c / phonegap-launch-navigator

Phonegap/Cordova plugin which launches native route navigation apps for Android, iOS and Windows
369 stars 129 forks source link

userChoice is undefined #198

Closed svarughese91 closed 5 years ago

svarughese91 commented 5 years ago

I'm submitting a ... (check one with "x"):

Bug report

Current behavior:

When I try to access if the user has selected a preferred nav app or try to set it I get a undefined error: TypeError: undefined is not an object (evaluating 'this.launchNavigator.appSelection.userChoice')

I pull this info directly from the plugin so not sure why it would be undefined. -->

Expected behavior:

This should be giving me a true or false to see if the user has selected a prefered nav app: this.launchNavigator.appSelection.userChoice.exists((doesExist) => {}) Steps to reproduce:

Environment information

Runtime issue

If using an [Ionic Native Typescript wrapper]() for this plugin:

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : ios 4.5.4
Ionic Framework    : ionic-angular 3.9.2

System:

ios-deploy : 1.9.2
Node       : v9.2.1
npm        : 2.15.12
OS         : macOS High Sierra
Xcode      : Xcode 9.4.1 Build version 9F2000

Environment Variables:

ANDROID_HOME : not set

Misc:

backend : pro
dpa99c commented 5 years ago

The userChoice object works fine (see screenshot below) - you can confirm this by building and running the AdvancedExample project in the example repo which makes use of userChoice.

The most likely cause of the error is the scope of this in your code is causing this.launchNavigator to be undefined - you can confirm this by debugging your code while it's running.

image

svarughese91 commented 5 years ago

@dpa99c how would i be able to access launchNavigator without using "this"?

dpa99c commented 5 years ago

Presumably you are using the Ionic Typescript wrapper for this plugin in which case you are not interacting directly with the plugin API.

The Cordova plugin API itself is pure Javascript, so as documented the plugin API is exposed via the global launchnavigator namespace on the window object:

window.launchnavigator....

or

launchnavigator...
svarughese91 commented 5 years ago

window['launchnavigator'] works! Thanks so much