Comments (1)
I was facing the same issue. Here is how I fixed it (iOS specific, android was working out of the box)-
- Uninstall the app from your phone
- Clear ALL the tokens stored in your database for this particular account(or however you have set it up in your backend. In my case, tokens are tied to the account)
- In componentDidmount-
async componentDidMount() {
this.checkPermission();
this.createNotificationListeners();
}
async checkPermission() {
const enabled = await firebase.messaging().hasPermission();
if (enabled) {
this.getToken();
} else {
this.requestPermission();
}
}
async requestPermission() {
try {
await firebase.messaging().requestPermission();
// User has authorised
this.getToken();
} catch (error) {
// User has rejected permissions
console.log('permission rejected');
}
}
async getToken() {
try {
const enabled = await firebase.messaging().hasPermission();
if (!enabled) {
await firebase.messaging().requestPermission();
}
const fcmToken = await firebase.messaging().getToken();
if (fcmToken) {
console.log("got token");
console.log('fcm token:', fcmToken); //-->use this token from the console to send a post request via postman
this.setState({ fcmToken });
return fcmToken;
}
} catch (error) {
console.warn('notification token error', error);
}
}
async createNotificationListeners() {
/*
* Triggered when a particular notification has been received in foreground
* */
this.notificationListener = firebase.notifications().onNotification((notification) => {
const { title, body } = notification;
this.showAlert(title, body);
});
/*
* If your app is in background, you can listen for when a notification is clicked / tapped / opened as follows:
* */
this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
const { title, body } = notificationOpen.notification;
this.showAlert(title, body);
});
/*
* If your app is closed, you can check if it was opened by a notification being clicked / tapped / opened as follows:
* */
const notificationOpen = await firebase.notifications().getInitialNotification();
if (notificationOpen) {
const { title, body } = notificationOpen.notification;
this.showAlert(title, body);
}
/*
* Triggered for data only payload in foreground
* */
this.messageListener = firebase.messaging().onMessage((message) => {
//process data message
console.log(JSON.stringify(message));
});
}
- Finally, use the token that you see in the console as a value for the "to" key in your post request. You should no longer see the "notRegistered" error and should be getting push notifications.
Done!!
For a more detailed setup/citation-
https://medium.com/@anum.amin/react-native-integrating-push-notifications-using-fcm-349fff071591
from mod_push_appserver.
Related Issues (20)
- Push handler for type 'fcm' not executed successfully: handler not found HOT 9
- lua5.2: arg no longer works for accessing variable arguments
- module:trigger does not exist
- Errors starting HOT 9
- unable to load apns HOT 1
- new errors starting up HOT 2
- attempt to index field '?' (a nil value) HOT 12
- require push_notification_important_body
- /healthcheck end point HOT 1
- Add support for Ubports (Ubuntu Touch) push notifications? HOT 1
- sslv3 negotiation issue HOT 1
- Could not tls-wrap APNS socket HOT 3
- Recommended configuration approach HOT 2
- purge invalid tokens HOT 1
- Slow event 'unregister-push-token' HOT 11
- Kick, invite, message and different notifications HOT 1
- apns connect error HOT 1
- loop or previous error loading module 'http.client'
- Can't serialize table: table has multiple references HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mod_push_appserver.