my app is crashed after receiving notification
export default class PushNotification extends Component { constructor(props) { super(props);
OneSignal.init('---------------------------------'); OneSignal.addEventListener("received", this.onReceived); OneSignal.addEventListener("opened", this.onOpened); OneSignal.addEventListener("ids", this.onIds); OneSignal.configure();
}
onReceived = notification => { console.log("Notification received: ", notification); };
onOpened = openResult => { console.log("Message: ", openResult.notification.payload.body); console.log("Data: ", openResult.notification.payload.additionalData); console.log("isActive: ", openResult.notification.isAppInFocus); console.log("openResult: ", openResult); };
onIds = device => { console.log("Device info: ", device); this.setState({ device }); };
sendNotification = data => { let headers = { "Content-Type": "application/json; charset=utf-8", Authorization: "Basic 'OneSignal Server Key'" };
let endpoint = "https://onesignal.com/api/v1/notifications"; let params = { method: "POST", headers: headers, body: JSON.stringify({ app_id: "-------------------------------------", included_segments: ["All"], contents: { en: data } }) }; fetch(endpoint, params).then(res => console.log(res));
}; componentDidMount() { this.sendNotification('Greeting from Chat App'); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
my app is crashed after receiving notification
export default class PushNotification extends Component {
constructor(props) {
super(props);
}
onReceived = notification => {
console.log("Notification received: ", notification);
};
onOpened = openResult => {
console.log("Message: ", openResult.notification.payload.body);
console.log("Data: ", openResult.notification.payload.additionalData);
console.log("isActive: ", openResult.notification.isAppInFocus);
console.log("openResult: ", openResult);
};
onIds = device => {
console.log("Device info: ", device);
this.setState({ device });
};
sendNotification = data => {
let headers = {
"Content-Type": "application/json; charset=utf-8",
Authorization: "Basic 'OneSignal Server Key'"
};
};
componentDidMount() {
this.sendNotification('Greeting from Chat App');
}