Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending notification to specific user #295

Closed
JoakimJohansen opened this issue Aug 4, 2017 · 2 comments
Closed

Sending notification to specific user #295

JoakimJohansen opened this issue Aug 4, 2017 · 2 comments

Comments

@JoakimJohansen
Copy link

JoakimJohansen commented Aug 4, 2017

I am currently working on a queue app and want users to get a notification when they are first in line.
I am very new to React Native and have never used One Signal before, but decided I wanted to use it.

All code below is part of my componentWillMount() method.
The part before the if-sentence is not working the way I want as I am not receiving any notification when OneSingal.postNotification(contents, data, playerId) is called. How should postNotification be formatted? Because right now nothing happens.

The part inside the sentence results in a error in the emulator when ran. Error is stating that the OneSignal.idsAvaliable() is not a function. I just tried to follow this; #4

  const data = null; // some array
  const contents = 'You are first in line';
  const playerId = '7997ab8f-3029-4e2c-b58e-3072e0284435';
  OneSignal.postNotification(contents, data, playerId);

//Checks current users place in line (if 1 a notification should be sent)
  if (this.props.place === 1) {
    console.log('you are first');
    OneSignal.idsAvailable((idsAvailable) => {
      console.log(idsAvailable.playerId);
      console.log(idsAvailable.pushToken);
      OneSignal.postNotification(contents, data, idsAvailable.playerId);
    });
  }

Any help would be much apreciated. I have gone through basically all information I could find on OneSignal and other similar threads. As I said I dont have much experience and the OneSignal documentation was not very helpful and too abstract. Thanks

@xinhash
Copy link

xinhash commented Sep 3, 2017

You should add the below line to your component will mount function
OneSignal.addEventListener("ids", this.onIds);
and have a function

onIds = device => {
    console.log(device.userId);
    console.log(device.pushToken);
}

@leoskyrocker
Copy link

change

const contents = 'You are first in line';

to

const contents = {'en': 'You are first in line'};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants