title: Cordova/Phonegap/Ionic - Receiving Push message via PushPlugin and save data to localStorage even when user dismisses the notification
body: <p>I have set up an Ionic Framework project which receives GCM push notifications. I want to save the incoming notifications in the window.localStorage of the app.</p>
  
  <p>This is what I have tried so far: </p>
  
  <pre><code>function onNotificationGCM(e) {
  switch( e.event )
  {
      case 'registered':
          if ( e.regid.length &gt; 0 )
          {
              //call back to web service in Angular
              var elem = angular.element(document.querySelector('[ng-app]'));
              var injector = elem.injector();
              var myService = injector.get('PushProcessingService');
              myService.registerID(e.regid);
          }
          break;
  
      case 'message':
  
          if (e.foreground)
          {
             //no problem here, this works as the app is already open
             window.localStorage['notifications'] = e.payload.message;
          }
          else
          {   
              //saving to localStorage in here works only when the user opens the app via the received notification
              if (e.coldstart)
                  window.localStorage['notifications'] = e.payload.message;
              else
                  window.localStorage['notifications'] = e.payload.message;
          }
  
          break;
  
      case 'error':
          break;
  
      default:
          break;
      }
  }
  </code></pre>
  
  <p>Saving to window.localStorage works if the app is already open when the notification arrives, but when the app is closed those methods will not get called. This will only happen if the user taps on the notification, which then opens the app.</p>
  
  <p>Is there a way to save notification data to the app's localStorage even if the user dismisses the incoming push notification?</p>
  
  <p>A work-around would be to store all notifications on a server and make the app retrieve them on opening, but I don't want to make the app slower by making unnecessary requests.</p>