2016-05-09 5 views
1

An Entwicklung App ionische Rahmen als Frontend und PHP-MySQL als Backend Gesamt Benachrichtigung Zahl zeigen. Implementiert die Push-Benachrichtigung mit Google GCM. Ich erhalte eine Push-Benachrichtigung, wenn etwas im Backend hinzugefügt wird.wie in ionischem App

folgende Funktion zu implementieren erforderlich: zeigen die Anzahl der Benachrichtigung über das App-Symbol in dem Startbildschirm empfangen.

Antworten geschätzt wird viel ..

Antwort

0

ionische Push-Benachrichtigung Probe https://github.com/hollyschinsky/PushNotificationSample

Badge Is Count for how `much notification successfully send.` 

    var buildPayload = function (options) { 
    var notif = new apn.Notification(options.payload); 

    notif.expiry = options.expiry || 0; 
    notif.alert = options.alert; 
    notif.badge = options.badge; 
    notif.sound = options.sound; 

    return notif; 
}; 


       if (notification.badge) { 
       $cordovaPush.setBadgeNumber(notif.badge).then(function (result) { 
        console.log("Set badge success " + result) 
       }, function (err) { 
        console.log("Set badge error " + err) 
       }); 
      } 
0

erstellen rootScope Variable notificationCount und den Wert dieser Variablen erhöhen Für jede Benachrichtigung

-Controller

$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) { 
    if (notification.badge) { 
     $cordovaPush.setBadgeNumber(notification.badge).then(function(result) { 
      $rootScope.notificationCount = notification.badge; 
     }, function(err) {}); 
    } 
}); 

HTML

<ion-side-menus enable-menu-with-back-views="false"> 
    <ion-side-menu-content> 
     <ion-nav-bar class="bar-light" align-title="left"> 
      <ion-nav-back-button> 
      </ion-nav-back-button> 
      <ion-nav-buttons side="left"> 
       <button class="button button-icon button-clear ion-navicon" menu-toggle="left"> 
       </button> 
      </ion-nav-buttons> 
      <ion-nav-buttons side="right"> 
       <button class="button button-icon home-notification-icon button-clear ion-ios-home" ng-click="openHome()"> 
       </button> 
       <button class="button button-icon button-clear home-notification-icon ion-android-notifications" badge="5" badge-style="badge-assertive"> 
        <span class="badge notification-badge badge-assertive header-badge">{{notificationCount}}</span> 
       </button> 
      </ion-nav-buttons> 
     </ion-nav-bar> 
     <ion-nav-view name="menuContent"></ion-nav-view> 
    </ion-side-menu-content> 
    <ion-side-menu side="left" style="background-color: #383839;"> 
     <ion-header-bar class="bar-stable"> 
      <img src="img/logo-web.png"> 
     </ion-header-bar> 
     <ion-content id="sidemenu"> 
      <!-- Your content goes here --> 
     </ion-content> 
    </ion-side-menu> 
</ion-side-menus> 
Verwandte Themen