Vova Bilyachat
Vova Bilyachat

Reputation: 19514

Ionic2 Push notification with background processing

I am using ionic.io to send push to my app. I have following body

{"tokens":["DeviceToken"],
"profile":"Profile",
"notification":{ "payload": {
      "type": "loadCategories"
    },
    "ios": {
      "content_available": 1
    },
    "android": {
      "content_available": "1"
    }}}

Type script code.

var push = Push.init({
                android: {
                    senderID: "ID"
                },
                ios: {
                    alert: "true",
                    badge: true,
                    sound: 'false'
                },
                windows: {}
            });
            if((<any>push).error) {
                console.log((<any>push).error);
                return;                
            };            
        push.on('registration', (data)=>{
            console.log(data.registrationId);
            this.pushToken = data.registrationId;
            this.updateToken();

        });
        push.on("notification", (data)=>{
            console.log(data);            
            // if(data.additionalData.payload && data.additionalData.payload.type == 'categoryEvent') {
            //     console.log("at date")
            // }
        });     
        push.on('error', function(e) {
            console.log(e.message);            
        });  

Idea is that I need to send push to user and load data from the server. But problem is that if app is in background then notification event is not fired. It works only if app is active. But as soon as i understand from documentation it should work.

Upvotes: 0

Views: 1687

Answers (1)

Wulf Solter
Wulf Solter

Reputation: 714

Known issue that has been addressed with setting content_available = 1. See https://github.com/phonegap/phonegap-plugin-push/issues/93 for more.

Upvotes: 3

Related Questions