我在应用程序中实现了android push接收,只要应用程序从该页面开始,它就可以很好地工作.但是,如果您导航到实现了推送通知的收件箱页面,则过渡将不起作用.
如果没有推送实施,过渡效果很好.
我想知道是否有人在实现功能时遇到了类似的问题.
.controller('BuzonMenuCtrl', function($scope, $window, $state, $ionicPlatform) {
$scope.botonBuzon = function(){
$state.go('buzon');
};
})
.controller('BuzonCtrl', function($scope, $rootScope, $window, $ionicActionSheet, $ionicPopup, $state, $http, dataFactory, pushFactory) {
// Activacion de la funcionalidad push
pushFactory.funcionalidadPush();
}
factorys.js
.factory('pushFactory', ['$rootScope','$http','$state','$ionicLoading','$ionicPlatform','$cordovaPush','dataFactory',
function($rootScope,$http,$state,$ionicLoading,$ionicPlatform,$cordovaPush,dataFactory) {
/* Objeto del factory */
var fac = {};
fac.funcionalidadPush = function(){
if (ionic.Platform.isAndroid()){
var androidConfig = {
"senderID": "94XXXXXXXXXX",
"ecb": "casosPush"
};
$rootScope.data.pushplatform = "gcm";
alert('Entro en modo Android');
};
if (ionic.Platform.isIOS()){
alert('Entro en modo iOS');
};
$ionicPlatform.ready(function() {
$cordovaPush.register(androidConfig).then(function(result) {
// Success
}, function(err) {
// Error
})
window.casosPush = function (notification) {
switch(notification.event) {
case 'registered':
if (notification.regid.length > 0 ) {
alert('registration ID = ' + notification.regid);
$rootScope.data.token = notification.regid;
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
//alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
$rootScope.mensajes.push(notification);
break;
case 'error':
alert('GCM error = ' + notification.msg);
break;
default:
alert('An unkNown GCM event has occurred');
break;
}
};
// WARNING: dangerous to unregister (results in loss of tokenID)
$cordovaPush.unregister(options).then(function(result) {
// Success!
}, function(err) {
// Error
})
}, false);
};
return fac;
}]);
App.js
angular.module('notPush', ['ionic', 'ngCordova', 'notPush.controllers'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('splash', {
url: '/splash',
templateUrl: 'templates/splash.html',
controller: 'SplashCtrl'
})
.state('buzonMenu', {
url: '/buzonMenu',
templateUrl: 'templates/buzonMenu.html',
controller: 'BuzonMenuCtrl'
})
.state('buzon', {
url: '/buzon',
templateUrl: 'templates/buzon.html',
controller: 'BuzonCtrl'
})
// If none of the above states are matched, use this as the fallback:
$urlRouterProvider.otherwise('/buzonMenu');
});
编辑
正如我在评论中所建议的
$window.location.reload(true);
除了使屏幕闪烁之外,它什么也没做
$state.go($state.current, {}, {reload: true});
它将尝试重新加载页面,但仅在损坏状态下,它将加载白色背景和按钮(无颜色),但仅加载其他内容.
编辑2一些澄清:
>用于推送通知的代码写在buzon_page控制器内部,该控制器有问题.
>当我说“过渡无效”时,是指该页面无法加载,但该页面的所有警报仍会触发,并且仍会检索“推送令牌”.是视觉问题,视图无法加载.
>该问题与HTTP调用无关,因为它们当前已被注释.
编辑3
我将通知代码移到了工厂,而不是将其放在控制器中(我想应该是这样),但是没有任何改善.
我在问题期间添加了adb logcat的结果.有两件事引起了我的注意:
>它在factorys.js中显示“ ReferenceError:未定义选项”
>它显示了一些Openglrenderer问题.
1219 AudioTrack W AUdio_OUTPUT_FLAG_FAST denied by client
2531 PushPlugin V execute: action=register
2531 PushPlugin V execute: data=[{"senderID":ID DELETED FOR PRIVACY ISSUES,"ecb":"casosPush"}]
2531 PushPlugin V execute: jo={"senderID":ID DELETED FOR PRIVACY ISSUES,"ecb":"casosPush"}
2531 PushPlugin V execute: ECB=casosPush senderID=ID DELETED FOR PRIVACY ISSUES
2531 GCMRegistrar D resetting backoff for ID DELETED FOR PRIVACY ISSUES
1219 InputMethodManager.. W Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@df31fbd attribute=null, token = a
ndroid.os.BinderProxy@28f2dc02
2531 GCMRegistrar V Registering app ID DELETED FOR PRIVACY ISSUES of senders ID DELETED FOR PRIVACY ISSUES
2531 SystemWebChromeCli.. D file:///android_asset/www/lib/ionic/js/ionic.bundle.js: Line 20243 : ReferenceError: options is not defined
2531 SystemWebChromeCli.. D at file:///android_asset/www/js/factorys.js:214:31
2531 SystemWebChromeCli.. D at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:44687:19
2531 SystemWebChromeCli.. D at Object.ionic.Platform.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:2120:9)
2531 SystemWebChromeCli.. D at Object.self.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:44685:26)
2531 SystemWebChromeCli.. D at Object.fac.funcionalidadPush (file:///android_asset/www/js/factorys.js:166:20)
2531 SystemWebChromeCli.. D at new <anonymous> (file:///android_asset/www/js/controllers.js:440:15)
2531 SystemWebChromeCli.. D at invoke (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:12821:17)
2531 SystemWebChromeCli.. D at Object.instantiate (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:12829:27)
2531 SystemWebChromeCli.. D at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17098:28
2531 SystemWebChromeCli.. D at self.appendViewElement (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:48110:24)
2531 chromium I [INFO:CONSOLE(20243)] "ReferenceError: options is not defined
2531 chromium I at file:///android_asset/www/js/factorys.js:214:31
2531 chromium I at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:44687:19
2531 chromium I at Object.ionic.Platform.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:2120:9)
2531 chromium I at Object.self.ready (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:44685:26)
2531 chromium I at Object.fac.funcionalidadPush (file:///android_asset/www/js/factorys.js:166:20)
2531 chromium I at new <anonymous> (file:///android_asset/www/js/controllers.js:440:15)
2531 chromium I at invoke (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:12821:17)
2531 chromium I at Object.instantiate (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:12829:27)
2531 chromium I at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17098:28
2531 chromium I at self.appendViewElement (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:48110:24)", source: file:///android_asset/www/lib/ionic
/js/ionic.bundle.js (20243)
1604 GCM D GcmService start Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms cmp=com.google.android.gms/.gcm.GcmServi
ce (has extras) } com.google.android.c2dm.intent.REGISTER
2531 GCMbroadcastReceiver V onReceive: com.google.android.c2dm.intent.REGISTRATION
2531 GCMRegistrar V Setting the name of retry receiver class to com.plugin.gcm.CordovaGCMbroadcastReceiver
2531 GCMbroadcastReceiver V GCM IntentService class: com.plugin.gcm.GCMIntentService
2531 GCMBaseIntentService V Acquiring wakelock
2531 GCMBaseIntentService V Intent service name: GCMIntentService-GCMIntentService-1
2531 GCMRegistrar V Registering receiver
2531 GCMBaseIntentService D handleRegistration: registrationId = TOKEN DELETED FOR PRIVACY ISSUES, error = null, unregistered = null
2531 GCMRegistrar D resetting backoff for ID DELETED FOR PRIVACY ISSUES
2531 GCMRegistrar V Saving regId on app version 10
2531 GCMIntentService V onRegistered: TOKEN DELETED FOR PRIVACY ISSUES
2531 GCMIntentService V onRegistered: {"event":"registered","regid":TOKEN DELETED FOR PRIVACY ISSUES}
2531 PushPlugin V sendJavascript: javascript:casosPush({"event":"registered","regid":TOKEN DELETED FOR PRIVACY ISSUES})
2531 GCMBaseIntentService V Releasing wakelock
2531 EGL_emulation W eglSurfaceAttrib not implemented
2531 Openglrenderer W Failed to set EGL_SWAP_BEHAVIOR on surface 0xa4cdd7e0, error=EGL_SUCCESS
1219 AudioTrack W AUdio_OUTPUT_FLAG_FAST denied by client
1219 InputMethodManager.. W Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@35215d0a attribute=null, token =
android.os.BinderProxy@28f2dc02
解决方法:
我将在此处添加我自己的代码,以防万一,警报和$rootScope变量用于测试目的.
/*
app.js
*/
angular.module('notPush', ['ionic', 'notPush.controllers', 'notPush.factorys'])
.run(function($ionicPlatform,$rootScope) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
$rootScope.mensajes = [];
// Push code
try{
var pushNotification = window.plugins.pushNotification;
} catch (ex){
}
var successfn = function(result){
alert("Success: " + result);
};
var errorfn = function(result){
window.alert("Error: " + result);
};
window.casosPush = function(notification){
switch (notification.event){
case 'registered':
if (notification.regid.length > 0){
alert('registration ID = ' + notification.regid);
}
break;
case 'message':
alert(JSON.stringify([notification]));
$rootScope.mensajes.push(notification);
break;
case 'error':
alert('GCM error = ' + notification.msg);
break;
default:
alert('An unkNown GCM event has occurred');
break;
}
};
try{
pushNotification.register(
successfn,
errorfn,
{
"senderID": "94XXXXXXXXXX",
"ecb" : "window.casosPush"
}
);
} catch(notification){
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('splash', {
url: '/splash',
templateUrl: 'templates/splash.html',
controller: 'SplashCtrl'
})
.state('registro', {
url: '/registro',
templateUrl: 'templates/registro.html',
controller: 'RegistroCtrl'
})
.state('buzonMenu', {
url: '/buzonMenu',
templateUrl: 'templates/buzonMenu.html',
controller: 'BuzonMenuCtrl'
})
.state('buzon', {
url: '/buzon',
templateUrl: 'templates/buzon.html',
controller: 'BuzonCtrl'
})
.state('detallesSimple', {
url: '/detallesSimple',
templateUrl: 'templates/detallesSimple.html',
controller: 'DetallesCtrl'
})
.state('detallesdoble', {
url: '/detallesdoble',
templateUrl: 'templates/detallesdoble.html',
controller: 'DetallesCtrl'
})
.state('detallesWV', {
url: '/detallesWV',
templateUrl: 'templates/detallesWV.html',
controller: 'DetallesWVCtrl'
})
// If none of the above states are matched, use this as the fallback:
$urlRouterProvider.otherwise('/splash');
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。