Экспо push-уведомление с FCM не хранит токен - PullRequest
0 голосов
/ 02 декабря 2019

Я новичок в React Native и мало знаком с бэкэндом, поэтому использую expo вместе с firebase для push-уведомлений. Весь мой код работает нормально без каких-либо ошибок, но всякий раз, когда я его запускаю, он не сохраняет мой токен в базе данных Firebase. Вот мой компонентDidMount ():

 componentDidMount() {
        var currentUser
        var that = this
        listener => db.auth().onAuthStateChanged(function (user) {
            if (user != null) {

                currentUser = user

                that.registerForPushNotificationsAsync(currentUser)
            }

            listener();

        });

        db.database().ref('/posts').on('child_added', function (data) {

            var newData = [...that.state.listViewData]
            newData.push(data)
            that.setState({ listViewData: newData })

        })
    }
```
And further my expo function for permissions and storing token is as follow:
```
 registerForPushNotificationsAsync = async (currentUser) => {
        const { existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
        let finalStatus = existingStatus;

        // only ask if permissions have not already been determined, because
        // iOS won't necessarily prompt the user a second time.
        if (existingStatus !== 'granted') {
            // Android remote notification permissions are granted during the app
            // install, so this will only ask on iOS
            const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
            finalStatus = status;
        }

        // Stop here if the user did not grant permissions
        if (finalStatus !== 'granted') {
            return;
        }

        // Get the token that uniquely identifies this device
        let token = await Notifications.getExpoPushTokenAsync();

        // POST the token to our backend so we can use it to send pushes from there
        var updates = {}
        updates['/expoToken'] = token
        await db.database().ref('/coordinator/' + currentUser.uid).update(updates)
        //call the push notification 
    }
```

[![This is my db on which expo token has to be stored][1]][1]



  [1]: https://i.stack.imgur.com/mT2A2.png
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...