2016-10-17 3 views
1

Я внедрил ионное push-уведомление на свое приложение для Android. Push-уведомление работает хорошо, когда приложение не работает (либо находится в фоновом режиме, либо не запущено), однако оно не получает уведомление о состоянии (панель уведомлений) или вибрацию, которая срабатывала при запуске в фоновом режиме или вообще не запускалась.Ионный PushNotification

$ionicPlatform.ready(function() { 

    localStorage.myPush = ''; // I use a localStorage variable to persist the token 
    var tokenID = ''; 
    $cordovaPushV5.initialize( // important to initialize with the multidevice structure !! 
     { 
      android: { 
       senderID: "457390407561" 
      }, 
      ios: { 
       alert: 'true', 
       badge: true, 
       sound: 'false', 
       clearBadge: true 
      }, 
      windows: {} 
     } 
    ).then(function (result) { 
     $cordovaPushV5.onNotification(); 
     $cordovaPushV5.onError(); 
     $cordovaPushV5.register().then(function (resultreg) { 
      localStorage.myPush = resultreg; 
      console.log(localStorage); 
     }, function (err) { 
      // handle error 
     }); 
    }); 

    $rootScope.$on('$cordovaPushV5:notificationReceived', function(event, data){ 
     // data.message, 
     // data.title, 
     // data.count, 
     // data.sound, 
     // data.image, 
     // data.additionalData 
     console.log("notification received"); 
     console.log(event); 
     console.log(data); 
     console.log(data.message); 
     console.log(data.title); 
     console.log(data.count); 
     console.log(data.sound); 

     if (data.additionalData.foreground === true) { 
     // do something if the app is in foreground while receiving to push - handle in app push handling 
     console.log("notification received in foreground"); 
     } 
     else { 
     // handle push messages while app is in background or not started 
     console.log("notification received in background"); 
     $state.go('app.orderlist'); 
     } 

    }); 
    // 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); 
     cordova.plugins.Keyboard.disableScroll(true); 
    } 
    if (window.StatusBar) { 
     // org.apache.cordova.statusbar required 
     StatusBar.styleDefault(); 
    } 
    }); 

Любые советы или предложения?

Заранее спасибо.

ответ

2

Вы можете добавить

forceShow: true 

, как показано ниже

$cordovaPushV5.initialize( // important to initialize with the multidevice structure !! 
     { 
      android: { 
       senderID: "xxxxxxxxx", 
       forceShow: true 
      }, 
      ios: { 
       alert: 'true', 
       badge: true, 
       sound: 'false', 
       clearBadge: true, 
      }, 
      windows: {} 
     } 
    ) 
Смежные вопросы