Notification push / One signal

yes, you need to import this in app.module

import { HttpModule } from '@angular/http';

and inside @ngModule on imports:

imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    HttpModule,
    AngularFireModule.initializeApp(config)
  ]

AngularFireModule is for initialize firebase, in case you didnt do that yet (config is a json with the api key and information of your firebase project)

var config = {
  apiKey: "***",
  authDomain: "***.firebaseapp.com",
  databaseURL: "https://***.firebaseio.com",
  projectId: "***",
  storageBucket: "***.appspot.com",
  messagingSenderId: "***"
};

And the token, yes. You need to store it somewhere, in a database if you use one for example.

1 Like

Okay, I’m starting to understand! I have no more error and it seems to walk in the console but how can I test? I try to put my own token to receive the notification but as I am already in the app I can not test …!

And two other things if it’s not too much … Thank you very much already! How do I get notifications when the app is not open at all? And how do we add a small badge on the application icon when we receive one?

in the firebase console, inside grow - notifications you can send notifications with the user token for testing.

this function in FCM act like a listener so you can set up a specefic behaviour when you open the app through a notification:

FCMPlugin.onNotification(function(data){
    if(data.wasTapped){
      //Notification was received on device tray and tapped by the user.
      alert( JSON.stringify(data) );
    }else{
      //Notification was received in foreground. Maybe the user needs to be notified.
      alert( JSON.stringify(data) );
    }
});

in android, when the app is launched the first time and then you close it , the app is still listening for notifications.

the badge in the app icon i think depends on the android version and mobile?, i am not sure, i dont think is something you can do with ionic.

1 Like

Okay thanks you again !

Yeah she is listening bug if we close it or if we reboot or device we will not received them …

Hmm on onesignal badge add automaticaly on the logo i will search by my self !

And also, how to request permission to send notifications ??

i don’t remember need to request permision for send notifications in android, did you get an error or something?

in ios i think you need it, but i didnt do that yet.

1 Like

The notification does not appear on my mobile, like facebook ect … It just appears in the notifications bar! If I want it to appear basically I have to go on my mobile in the notifications options of this application and add the options to make it appear at wholesale

Should i use
//FCMPlugin.onTokenRefresh( onTokenRefreshCallback(token) );
//Note that this callback will be fired everytime a new token is generated, including the first time.
FCMPlugin.onTokenRefresh(function(token){
alert( token );
});

instead of get token ?

what do you mean like facebook?

the notification only appear if the app is closed or minimize, if you are inside your app you can set up an alert or something, in the else statement of “onNotification” function.

the token can be changed in any moment by firebase, the onTokenRefresh function is another listener that trigger when the token is change, so you can save it again

1 Like

I mean, like on the screen behind, and me i have just the notification in the notifications bar ! But i can fix this, in the option of my device … but if all people need to go in the settings this is not fine.

Okay thanks you !

images

@rude5446 Hi, sorry to disturb again but I really have a hard time with this notification story when the app is totally closed … I get the notifications ect perfectly when I’m on it or it’s in the background but when it’s totally close nothing at all … an idea …

you are using ios, right?

are you using “priority”: “high” when you send notifications?

1 Like

I use Android and yes i use priority high

I have seen that several places it speaks of the file MyFirebaseMessagingService. I need to change something inside this one?

can you post your notification payload?

and when you mean totally closed, you mean force close? like going to settings - apps and find the app and force quit?

1 Like

I do not receive them when the application is completely closed even using the firebase send directly without method! The payload, is the method I did to send notifications from within?

This would not come from the file “MyFirebaseMessagingService.java”? I see that some people modify it!

When I say totally close I’m talking about that yes, when we do not turn on the application at all or turn it on and close forcibly

Thanks for help

@rude5446 I mean when i swipe close from the app open not going in settings

@rude5446 Okay … on samsung its work ! That’s come from huawei service and asus ^^ Really thanks for your help !

how to send notifications to all users, show error: "Notification Post Failed: Please include a case-sensitive header of Authorizathion: Basic with a valid REST PI KEY … " THANK YOU