App is run forever


#1

Hi ,

i am using ionic 2 with pushnotification.

used this plugin ionic plugin add phonegap-plugin-push

It’s work only on app is running.

I need app is running forever like whatsup.

i also used cordova background mode.

Still not work

how can i able to do this.

can u please help me.

Thanks & regards


#3

Then you didn’t implement correctly. Push notifications work always, also when the app is not running or in background.


#4

Thanks for ur response.May be my code is incorrect.Kindly give me idea for app is keep running forever.


#5

phonegap-plugin-push will never receive push noti. if your app is closed.
Try using OneSignal plugin.
It will receive notification even though your app is closed.


#6

Thanks for ur reply.I have one doubt.can i used onesignalplugin for FCM/GCM pushnotification?
and also what is the googleProjectNumber


#7

you need to make account on onesignal website. and there you will have to provide your GCM server key and sender ID.


#8

something like this.


#9

Thank u.Is Notification receive also app not running ?


#10

Yeah… i am using it and it’s receiving notification even though app is closed.


#11

@ravi_sojitra Thanks for ur patient.I have account for onesignal website also i created a new app.

How can i get Google project Number?


#12

Google project number means sender id from your firebase account.


#13

i am getting this err ERROR Error: Uncaught (in promise): plugin_not_installed.But i installed the plugin using this

ionic cordova plugin add onesignal-cordova-plugin


#14

Can you show me your code where you are using that plugin?
Did you wrap that code inside platform.ready() function?


#15

Here is my code

import { Component } from ‘@angular/core’;
import { NavController } from ‘ionic-angular’;
import { OneSignal } from ‘@ionic-native/onesignal’;

@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {

constructor(private oneSignal: OneSignal,public navCtrl: NavController) {
this.oneSignal.startInit(‘5d4fd62b-b9f8-4e41-9a89-7ea3b18af3de’,‘470761651487’);

this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);

this.oneSignal.handleNotificationReceived().subscribe((d) => {
	// do something when notification is received
	console.log("NOTIFICATION RECEIVED");
	console.log(d);
});

this.oneSignal.handleNotificationOpened().subscribe((d1) => {
  	// do something when a notification is opened
  	console.log("NOTIFICATOIN OPENED");
  	console.log(d1);

});

this.oneSignal.endInit();

}

}

I also import app module…


#16

Wrap your code inside platform.ready() function.


import { NavController,Platform } from 'ionic-angular'; //import platform
@Component({
   selector: 'page-home',
   templateUrl: 'home.html'
})
export class HomePage {

    constructor(private oneSignal: OneSignal,public navCtrl: NavController,public platform:Platform) { // add platform here
        platform.ready().then(()=>{ //add this function

            this.oneSignal.startInit('5d4fd62b-b9f8-4e41-9a89-7ea3b18af3de','470761651487');

            this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.InAppAlert);

            this.oneSignal.handleNotificationReceived().subscribe((d) => {
                // do something when notification is received
                console.log("NOTIFICATION RECEIVED");
                console.log(d);
            });

            this.oneSignal.handleNotificationOpened().subscribe((d1) => {
                // do something when a notification is opened
                console.log("NOTIFICATOIN OPENED");
                console.log(d1);

            });

            this.oneSignal.endInit();
        });
    }

}

#17

Ya.It’s wrk.How can i send notification?


#18

In onesignal dashboard you will find New Message in left side menu.
Fille up the details and send notification from there.


#19

@ravi_sojitra. i try to send notifications.I got this err msg

My device cannot receive notifications.Can u explain briefly


#20

Did you open an app because it needs to be opened once to register your app to onesignal.
If you did then
add this function after this.oneSignal.startInit('5d4fd62b-b9f8-4e41-9a89-7ea3b18af3de','470761651487');
line

this.oneSignal.getIds().then((ids)=>{
        alert(ids.userId);
      }).catch((e)=>{
        alert(e);
      })

and let me know what did you get.


#21

Yeah.I got ids.userID.