评级插件不适用于Ionic 3

时间:2017-11-07 11:43:05

标签: angular typescript ionic3 cordova-plugins ionic-native

我遵循了本教程:http://ionicframework.com/docs/native/app-rate/

我使用第二种方法,但是我收到了这个错误:

  

未捕获(承诺):TypeError:无法读取属性' split'的   undefined TypeError:无法读取属性' split'未定义的       在Function.Locales.getLocale(http://192.168.1.2:8100/plugins/cordova-plugin-apprate/www/locales.js:53:74)       在showDialog(http://192.168.1.2:8100/plugins/cordova-plugin-apprate/www/AppRate.js:91:29)       在Function.AppRate.promptForRating(http://192.168.1.2:8100/plugins/cordova-plugin-apprate/www/AppRate.js:203:7)       at callCordovaPlugin(http://192.168.1.2:8100/build/vendor.js:77234:43)       在http://192.168.1.2:8100/build/vendor.js:77260:28       在http://192.168.1.2:8100/build/vendor.js:58635:17       在新的t(http://192.168.1.2:8100/build/polyfills.js:3:20886)       在tryNativePromise(http://192.168.1.2:8100/build/vendor.js:58634:20)       at getPromise(http://192.168.1.2:8100/build/vendor.js:58642:12)       在wrapPromise(http://192.168.1.2:8100/build/vendor.js:77243:78

如果我删除此行,则不会触发评级,但没有其他任何操作失败: this.appRate.promptForRating(true);

这是我使用的插件: https://github.com/pushandplay/cordova-plugin-apprate

2 个答案:

答案 0 :(得分:2)

有同样的问题,我在添加此行后能够看到弹出对话框;

  

useLanguage:' en',

出现了另一个错误,使用下面的回调函数很容易修复;

  callbacks: {
    onButtonClicked: function (buttonIndex) {
      console.log("onButtonClicked -> " + buttonIndex);
    }

答案 1 :(得分:0)

这很好用。我得到了这个from here

import { AppRate } from '@ionic-native/app-rate';
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { HomePage } from '../pages/home/home';
@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage: any = HomePage;

  constructor(platform: Platform, private appRate: AppRate, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();

      this.appRate.preferences = {
        openStoreInApp: false,
        displayAppName: 'Simons App',
        usesUntilPrompt: 2,
        promptAgainForEachNewVersion: false,
        storeAppURL: {
          ios: '1216856883',
          android: 'market://details?id=com.devdactic.crossingnumbers'
        },
        customLocale: {
          title: 'Do you enjoy %@?',
          message: 'If you enjoy using %@, would you mind taking a moment to rate it? Thanks so much!',
          cancelButtonLabel: 'No, Thanks',
          laterButtonLabel: 'Remind Me Later',
          rateButtonLabel: 'Rate It Now'
        },
        callbacks: {
          onRateDialogShow: function(callback){
            console.log('rate dialog shown!');
          },
          onButtonClicked: function(buttonIndex){
            console.log('Selected index: -> ' + buttonIndex);
          }
        }
      };

      // Opens the rating immediately no matter what preferences you set
      this.appRate.promptForRating(true);
    });
  }
}