Cordova / Phonegap / Ionic - receiving a Push message through PushPlugin and saving data to localStorage, even when the user rejects the notification

I created an Ionic Framework project that receives notifications of the GCM push method. I want to save incoming notifications in the window.localStorage application.

This is what I have tried so far:

function onNotificationGCM(e) {
switch( e.event )
{
    case 'registered':
        if ( e.regid.length > 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;
    }
}

Saving to window.localStorage works if the application is already open when a notification arrives, but when the application is closed, these methods will not be called. This will only happen if the user hits a notification, which then opens the application.

Is there a way to save notification data in the local application store even if the user rejects the incoming push notification?

, , , , .

+4
1

, GCM , . . , - , . , , localStorage, .

. , , .

0

Source: https://habr.com/ru/post/1545582/


All Articles