App Availability Code Error


#1

I am trying to use App Availability extension. But i am getting error even when i am using the same example. Please Take a look below.

openTwitterApp(){
    let app;
    if (this.platform.is('ios')) {
      app = 'twitter://';
    } else if (this.platform.is('android')) {
      app = 'com.twitter.android';
    }
    this.appAvailability.check(app)
    .then(
      (yes: string) => console.log(app + ' is available'),
      (no: string) => console.log(app + ' is NOT available')
    );
  }


#2

Where does this variable come from?
Are you using Ionic Native?


#3

yes i am using Ionic Native


#4

What error are you getting? Or should we guess?


#5
[ts]
Argument of type '(yes: string) => void' is not assignable to parameter of type '(value: boolean) => void | PromiseLike<void>'.
  Types of parameters 'yes' and 'value' are incompatible.
    Type 'boolean' is not assignable to type 'string'.

This is the error…


#6

Their example (Ionic native) seem to be wrong. The check function returns a Promise<boolean> as per the documentation and the error message say, not a Promise<string> like in the example.
Try this

this.appAvailability.check(app)
  .then(
    () => console.log(app + ' is available'),
    () => console.log(app + ' is NOT available')
  );

If that doesn’t work then maybe this

this.appAvailability.check(app)
  .then(
    (available: boolean) => {
        if (available) {
            console.log(app + ' is available')
        } else {
            console.log(app + ' is NOT available')
        }
    })
  );

Either way I think the documentation is wrong if you’re getting an error with the example