ngCordova有一个插件叫AppRate
,可以用于APP评分,先看我们让让最后的效果图。
1.安装Cordova插件
cordova plugin add https://github.com/pushandplay/cordova-plugin-apprate.git
2.配置
正常的配置如官方所示:
module.config(function ($cordovaAppRateProvider) {
document.addEventListener("deviceready", function () {
var prefs = {
language: 'en',
appName: 'MY APP',
iosURL: '<my_app_id>',
androidURL: 'market://details?id=<package_name>',
windowsURL: 'ms-windows-store:Review?name=<...>'
};
$cordovaAppRateProvider.setPreferences(prefs)
}, false);
});
而,我还想修改上面的文字,谁让我不喜欢官方的中文翻译呢?这时我们需要用到
$cordovaAppRateProvider.setPreferences(prefs);
于是,最后我们的配置如下所示
module.config(function ($cordovaAppRateProvider) {
document.addEventListener("deviceready", function () {
var prefs = {
language: 'zh-Hans',
appName: '教你设计物联网',
androidURL: 'market://details?id=com.phodal.designiot'
};
var strings = {
title: '动动手指,为我们打分',
message: '无论是来自亲的赞美诗,还是让亲唾沫横飞的槽点,我们只愿——让评价来得更猛烈些吧!',
cancelButtonLabel: '残忍地拒绝',
laterButtonLabel: '容我考虑考虑',
rateButtonLabel: '马上就去'
};
$cordovaAppRateProvider.setCustomLocale(strings);
$cordovaAppRateProvider.setPreferences(prefs);
}, false);
})
3.调用
一个简单的调用可以是
module.controller('MyCtrl', function($scope, $cordovaAppRate) {
document.addEventListener("deviceready", function () {
$cordovaAppRate.navigateToAppStore().then(function (result) {
// success
});
}, false);
});
也可以是和我一样的:
.controller('AccountCtrl', function ($scope, $cordovaAppRate) {
$scope.promptRating = function () {
$cordovaAppRate.promptForRating(true).then(function (result) {
console.log("result: " + result);
$scope.words = result;
}, function (error) {
$scope.words = result;
})
};
}
接着在页面上添加一个ng-click
<a class="button button-full" href="#" ng-controller="AccountCtrl" ng-click="promptRating()">
<i class="ion-ios-star-outline"></i>
评价
</a>
围观我的Github Idea墙, 也许,你会遇到心仪的项目