pushandplay / cordova-plugin-apprate

This plugin provide the "rate this app" functionality into your Cordova/Phonegap application
Apache License 2.0
298 stars 192 forks source link

cordova.js:308 Uncaught TypeError: AppRate.preferences.openUrl is not a function #263

Open nidhivc opened 4 years ago

nidhivc commented 4 years ago

cordova.js:308 Uncaught TypeError: AppRate.preferences.openUrl is not a function

at Function.AppRate.navigateToAppStore (AppRate.js:257) at promptForStoreRatingWindowButtonClickHandler (AppRate.js:85) at Object.callbackFromNative (cordova.js:287) at :1:9

sensuy commented 4 years ago

Same to me!

cordova.js:308 Uncaught TypeError: AppRate.preferences.openUrl is not a function at Function.AppRate.navigateToAppStore (AppRate.js:257) at promptForStoreRatingWindowButtonClickHandler (AppRate.js:85) at Object.callbackFromNative (cordova.js:287) at :1:9

sensuy commented 4 years ago

[SOLVED] -> doing the downgrade to "@ionic-native/app-rate": "^5.15.1" and "cordova-plugin-apprate": "^1.4.0"

Edited: Sorry I forgot to say that im using Ionic CLI: 5.4.4, Ionic Framework : @ionic/angular 4.11.2 @angular-devkit/build-angular : 0.13.9 @angular-devkit/schematics : 7.3.9 @angular/cli : 7.3.9 @ionic/angular-toolkit : 1.5.1

nidhivc commented 4 years ago

I am working on ionic3 ,by using your solution it gives me Apprate referes to a value ,but it is being use as a type here. also gives ionic-app-script task: "build" [10:46:19] Error: Failed to transpile program Error: Failed to transpile program at new BuildError when try to generate build

nidhivc commented 4 years ago

I have install "@ionic-native/app-rate": "^4.20.0", "cordova-plugin-apprate": "^1.4.0", ionic - 3 versions

ryaa commented 4 years ago

From the plugin docs:

NOTE: If you chose inappbrowser then make sure to add openUrl: AppRate.preferences.openUrl option to preferences if you will override the preference object. And if you chose cordova-plugin-safariviewcontroller then you must configure it with this plugin by setting

The typing does not seem to have openURL prop added yet - see https://github.com/pushandplay/cordova-plugin-apprate/pull/261 (for @ionic-native/app-rate as well)

As a temporary fix I did the following 1) added new interface

interface AppRatePreferencesEnhanced extends AppRatePreferences {
  openUrl: (url: string) => void;
}

2) used it as below

  const preferences: AppRatePreferencesEnhanced = {
     displayAppName: 'My custom app title',
     usesUntilPrompt: 5,
     promptAgainForEachNewVersion: false,
     inAppReview: true,
    storeAppURL: {
      ios: '<my_app_id>',
      android: 'market://details?id=<package_name>',
      windows: 'ms-windows-store://pdp/?ProductId=<the apps Store ID>',
      blackberry: 'appworld://content/[App Id]/',
      windows8: 'ms-windows-store:Review?name=<the Package Family Name of the application>'
    },
    customLocale: {
      title: "Would you mind rating %@?",
      message: "It won’t take more than a minute and helps to promote our app. Thanks for your support!",
      cancelButtonLabel: "No, Thanks",
      laterButtonLabel: "Remind Me Later",
      rateButtonLabel: "Rate It Now",
      yesButtonLabel: "Yes!",
      noButtonLabel: "Not really",
      appRatePromptTitle: 'Do you like using %@',
      feedbackPromptTitle: 'Mind giving us some feedback?',
    },
    callbacks: {
      handleNegativeFeedback: function(){
        window.open('mailto:feedback@example.com','_system');
      },
      onRateDialogShow: function(callback){
        callback(1) // cause immediate click on 'Rate Now' button
      },
      onButtonClicked: function(buttonIndex){
        console.log("onButtonClicked -> " + buttonIndex);
      }
    },
    openUrl: (this.appRate.preferences as AppRatePreferencesEnhanced).openUrl
  };
    this.appRate.preferences = preferences;
    this.appRate.promptForRating(false);

This works fine with the latest version of this plugin and in ionic 3 app

westonganger commented 4 years ago

The typings file is now fixed in master via #261

ryaa commented 4 years ago

The typings file is now fixed in master via #261

any plans to release it soon? thank you

SebastianLms commented 4 years ago

From the plugin docs:

NOTE: If you chose inappbrowser then make sure to add openUrl: AppRate.preferences.openUrl option to preferences if you will override the preference object. And if you chose cordova-plugin-safariviewcontroller then you must configure it with this plugin by setting

The typing does not seem to have openURL prop added yet - see #261 (for @ionic-native/app-rate as well)

As a temporary fix I did the following

  1. added new interface
interface AppRatePreferencesEnhanced extends AppRatePreferences {
  openUrl: (url: string) => void;
}
  1. used it as below
  const preferences: AppRatePreferencesEnhanced = {
     displayAppName: 'My custom app title',
     usesUntilPrompt: 5,
     promptAgainForEachNewVersion: false,
     inAppReview: true,
    storeAppURL: {
      ios: '<my_app_id>',
      android: 'market://details?id=<package_name>',
      windows: 'ms-windows-store://pdp/?ProductId=<the apps Store ID>',
      blackberry: 'appworld://content/[App Id]/',
      windows8: 'ms-windows-store:Review?name=<the Package Family Name of the application>'
    },
    customLocale: {
      title: "Would you mind rating %@?",
      message: "It won’t take more than a minute and helps to promote our app. Thanks for your support!",
      cancelButtonLabel: "No, Thanks",
      laterButtonLabel: "Remind Me Later",
      rateButtonLabel: "Rate It Now",
      yesButtonLabel: "Yes!",
      noButtonLabel: "Not really",
      appRatePromptTitle: 'Do you like using %@',
      feedbackPromptTitle: 'Mind giving us some feedback?',
    },
    callbacks: {
      handleNegativeFeedback: function(){
        window.open('mailto:feedback@example.com','_system');
      },
      onRateDialogShow: function(callback){
        callback(1) // cause immediate click on 'Rate Now' button
      },
      onButtonClicked: function(buttonIndex){
        console.log("onButtonClicked -> " + buttonIndex);
      }
    },
    openUrl: (this.appRate.preferences as AppRatePreferencesEnhanced).openUrl
  };
    this.appRate.preferences = preferences;
    this.appRate.promptForRating(false);

This works fine with the latest version of this plugin and in ionic 3 app

This temporally fix works for me, thanks for sharing.

aaronetto commented 4 years ago

I had the same issue (AppRate.preferences.openUrl is not a function) with ionic 4, then i could resolve these using the spread operator.

    this.appRate.preferences = {
      ...this.appRate.preferences,
      storeAppURL: {
        ios: "XXXXXX",
        android: "market://details?id=com.xxxx.xxxx"
      },
      simpleMode: true,
      useLanguage: "en",
      customLocale: {
        title: "rate my App",
        message: "Some message"
      },
      // Rest of custom properties here!
    }

    this.appRate.promptForRating(true);

Regards!

thomashrabe commented 4 years ago

I do not understand what the internal this.appRate.preferences should be. It 's undefined for me. Is this above not a circular dependency?

ShTaras commented 4 years ago

this.appRate.preferences.openUrl = () => { window.open(this.appRate.preferences.storeAppURL.android); };

umsuka commented 4 years ago

I had the same issue (AppRate.preferences.openUrl is not a function) with ionic 4, then i could resolve these using the spread operator.

    this.appRate.preferences = {
      ...this.appRate.preferences,
      storeAppURL: {
        ios: "XXXXXX",
        android: "market://details?id=com.xxxx.xxxx"
      },
      simpleMode: true,
      useLanguage: "en",
      customLocale: {
        title: "rate my App",
        message: "Some message"
      },
      // Rest of custom properties here!
    }

    this.appRate.promptForRating(true);

Regards!

Thanks this worked for me for Ionic 5

Syalcindag commented 4 years ago

From the plugin docs:

NOTE: If you chose inappbrowser then make sure to add openUrl: AppRate.preferences.openUrl option to preferences if you will override the preference object. And if you chose cordova-plugin-safariviewcontroller then you must configure it with this plugin by setting

The typing does not seem to have openURL prop added yet - see #261 (for @ionic-native/app-rate as well) As a temporary fix I did the following

  1. added new interface
interface AppRatePreferencesEnhanced extends AppRatePreferences {
  openUrl: (url: string) => void;
}
  1. used it as below
  const preferences: AppRatePreferencesEnhanced = {
     displayAppName: 'My custom app title',
     usesUntilPrompt: 5,
     promptAgainForEachNewVersion: false,
     inAppReview: true,
    storeAppURL: {
      ios: '<my_app_id>',
      android: 'market://details?id=<package_name>',
      windows: 'ms-windows-store://pdp/?ProductId=<the apps Store ID>',
      blackberry: 'appworld://content/[App Id]/',
      windows8: 'ms-windows-store:Review?name=<the Package Family Name of the application>'
    },
    customLocale: {
      title: "Would you mind rating %@?",
      message: "It won’t take more than a minute and helps to promote our app. Thanks for your support!",
      cancelButtonLabel: "No, Thanks",
      laterButtonLabel: "Remind Me Later",
      rateButtonLabel: "Rate It Now",
      yesButtonLabel: "Yes!",
      noButtonLabel: "Not really",
      appRatePromptTitle: 'Do you like using %@',
      feedbackPromptTitle: 'Mind giving us some feedback?',
    },
    callbacks: {
      handleNegativeFeedback: function(){
        window.open('mailto:feedback@example.com','_system');
      },
      onRateDialogShow: function(callback){
        callback(1) // cause immediate click on 'Rate Now' button
      },
      onButtonClicked: function(buttonIndex){
        console.log("onButtonClicked -> " + buttonIndex);
      }
    },
    openUrl: (this.appRate.preferences as AppRatePreferencesEnhanced).openUrl
  };
    this.appRate.preferences = preferences;
    this.appRate.promptForRating(false);

This works fine with the latest version of this plugin and in ionic 3 app

This temporally fix works for me, thanks for sharing.

this worked but now this error

E/Capacitor/Console: File: capacitor-runtime.js - Line 362 - Msg: TypeError: Cannot read property 'open' of undefined E/Capacitor: JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read property 'open' of undefined","url":"capacitor-runtime.js","line":1358,"col":21,"errorObject":"{}"}} E/Capacitor/Console: File: capacitor-runtime.js - Line 1358 - Msg: Uncaught TypeError: Cannot read property 'open' of undefined

wiwimaster commented 4 years ago

I had the same issue (AppRate.preferences.openUrl is not a function) with ionic 4, then i could resolve these using the spread operator.

    this.appRate.preferences = {
      ...this.appRate.preferences,
      storeAppURL: {
        ios: "XXXXXX",
        android: "market://details?id=com.xxxx.xxxx"
      },
      simpleMode: true,
      useLanguage: "en",
      customLocale: {
        title: "rate my App",
        message: "Some message"
      },
      // Rest of custom properties here!
    }

    this.appRate.promptForRating(true);

Regards!

That's super quick and did solve the issue for me!

mayankkataria commented 2 years ago

For android, adding below line to preferences worked for me - openUrl: (url) => window.open(url, '_blank', 'location=yes')