.run(['$rootScope','$ionicPlatform','$state','$filter','$ionicHistory',
function($rootScope,$ionicPlatform,$state,$filter,$ionicHistory) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
var os = $filter('os')();
$rootScope.isIos = false;
function setBar(){
// 设置状态栏背景颜色
if(os == "ios"){
// alert("00");
$rootScope.isIos = true;
//var color = $filter("hex")($(".bar-header").css("background-color")); //获取颜色,并过滤为hex色值
plus.navigator.setStatusBarBackground("#007AFF"); //color必须为hex值
plus.navigator.setStatusBarStyle('UIStatusBarStyleBlackOpaque'); //设置顶栏
}else{
console.log('返回 001');
var first = null;
plus.key.addEventListener("backbutton",function(){
if($state.is('app.playlists')){
console.log('返回 002');
if(!first){
first = new Date().getTime();
$rootScope.showTip('再次点击退出应用');
setTimeout(function(){
first = null;
},1000);
}else{
if(new Date().getTime()-first<1500){
plus.runtime.quit();
}
}
}else{
console.log('返回 003');
if(!$state.is('app.rentalhouseAdd')){
console.log('返回 004');
$ionicHistory.goBack();
}
// $ionicHistory.goBack();
}
});
}
//关闭启动画面
plus.navigator.closeSplashscreen();
}
//初始化plus对象
if (window.plus) {
setBar();
} else {
document.addEventListener("plusready", setBar, false);
}
});
}])
如上述代码,hbuilder打包后,安卓手机的返回键没有效果,请大神看一下,是不是哪里用的不对,确认进入了setBar方法,但是一个alert都不弹出
本地真机模拟是好的,控制台也输出了对应的console,打包就不行,求指教!
1 个回复
赵梦欢 - 专注前端,乐于分享!
http://ask.dcloud.net.cn/question/27055