Notification push / One signal


#1

Hello,

I try to make notifications for my application, I managed to set up notifications with OneSignal! it allows me to send notifications to ALL users.

However, I try to make sure to sent, for example a notification to a particular person when she received a comment …

Someone know how to do it? I did some testing but nothing came up …

Thank you


#2

I give up with onesignal, i recommend firebase and this plugin:

so much easy to target specefic users


#3

Thanks for reply, i will try with that, can you give me an exemple of how its works ?


#4

First you need to create a project in firebase

https://console.firebase.google.com

For android it will genetare a file call google_services.json that you need to put in the root folder of your project.

then you need to initialize firebase in your project following the official docs

https://firebase.google.com/docs/web/setup

I use the official library for angular2

Then FCMPlugin has different functions to retrieve tokens for users, later use for target that users, that you can save where you want, and functions for upcoming notifications.

Finally you build and send a notification like this:

let headers = new Headers({ 'Authorization': 'key=YOUR_API_KEY', 'Content-Type': 'application/json' });
          let options = new RequestOptions({ headers: headers });
          let notification = {
            "notification": {
              "title": NOTIFICATION_TITLE,
              "body": NOTIFICATION_BODY,
              "click_action": "FCM_PLUGIN_ACTIVITY",
              "sound": "default"
            }, "data": {
              //OPTIONAL PARAMS
            },
            "to": USER_TOKEN,
            "priority": "high"
          }
          let url = 'https://fcm.googleapis.com/fcm/send';
          this.http.post(url, notification, options)

Hope this will help you, i am not the best explaining things


#5

Hmm … Is this work when the application is not open ?


#6

Sure It works. :slight_smile:


#7

I can not do it … I try to do the steps but it does not work … I can not finalize my application without notifications … I use the command to install FCM, after I connected my application android a firebase and I put a method … I’m not even what it serves I do not understand the system of notifications … It’s so difficult?


#8

I follow this tutoriel : https://www.youtube.com/watch?v=IF09XbGfOu8 but not working for me …


#9

if you want to send to someone specifically you need to send data with include_player_ids: [player_id_array] you can take a look at this link https://documentation.onesignal.com/v3.0/reference


#10

Thank you for your answer, I already saw this documentation but I can not apply it … I have no concrete example


#11

take a look at the docs https://ionicframework.com/docs/native/onesignal/ and you can search in the net for other examples… there are so many examples of it…


#12

I tried, all that I put in place, the problem is to send a notification from the application, for example when a person puts a comment to another person it sends him a notification


#13

yeah you can achieve it with one signal you just need to study and make the installation of OneSignal correct…


#14

I already done that :
app.component.ts :
(in constructor)
Capture


app.module.ts :
Capture

Capture


#15

anything in the OneSignal dashboard? list of users(player_id)??


#16

Yeah in the method i use the player id ! Now i need too implement a new method who send a notifications, so i open a page i call the method on a click (for test) and i put the code from the documentation in node JS and that’s not work …


#17

any console.log errors?


#18

I cant use the console, i can’t use the ionic serve because of the method in the app.component.ts


#19

I just run into my devices for try


#20

you can see the console.log using chrome://inspect (connect your device to the computer)