TypeError: Undefined не является объектом (оценивает '_pushNotifications.pushNotifications.configure') React Native - PullRequest
0 голосов
/ 04 мая 2020

Я новичок в React Native и пытаюсь создать уведомления pu sh на iOS с pu sh -notification- ios и response-native-pu sh-уведомлением. Я изучаю несколько различных руководств по этому вопросу, поскольку я все еще изучаю, как это работает.

Когда я запускаю свое приложение, я получаю следующую ошибку.

error

Вот мой код

const configure = async () => {
    console.log('push notification configured');
    PushNotificationIOS.addEventListener('registrationError', (e) => {

    PushNotifcation.configure({
        
        onRegister: function(token) {
            //process token
            alert('Token!' + JSON.stringify(token));
            console.log('[CATCHED] onRegister:', token);
            db.setToken(token).catch(
               console.log('[ERROR] device push token has not been saved on the database'), 
            );
        },
        onNotification: async function(notification) {
            console.log('[CATCHED] onNotification:' + JSON.stringify(notification));
            let notifType = '';
            if (Platform.OS === 'ios') {
                notifType = getNotificationType(
                    JSON.parse(notification.data.data).type,
                );
            } else {
                notifType = getNotificationType(
                    notification.type,
                );
            }
            //process the notification
            //required on iOS only
            if (Platform.OS === 'ios') {
            notification.finish(PushNotificationIOS.FetchResult.NoData);
            }
            },
            senderID: '-----',

        permissions: {
            alert: true,
            badge: true,
            sound: true
        },

        popInitialNotification: true,
        requestPermissions: true,
    });
    });
}

export {
    configure,
};

1 Ответ

0 голосов
/ 08 мая 2020

Строка 5: вы набрали PushNotifcation вместо PushNotification.

Фиксированный код здесь:

const configure = async () => {
    console.log('push notification configured');
    PushNotificationIOS.addEventListener('registrationError', (e) => {

    PushNotification.configure({

        onRegister: function(token) {
            //process token
            alert('Token!' + JSON.stringify(token));
            console.log('[CATCHED] onRegister:', token);
            db.setToken(token).catch(
               console.log('[ERROR] device push token has not been saved on the database'), 
            );
        },
        onNotification: async function(notification) {
            console.log('[CATCHED] onNotification:' + JSON.stringify(notification));
            let notifType = '';
            if (Platform.OS === 'ios') {
                notifType = getNotificationType(
                    JSON.parse(notification.data.data).type,
                );
            } else {
                notifType = getNotificationType(
                    notification.type,
                );
            }
            //process the notification
            //required on iOS only
            if (Platform.OS === 'ios') {
                notification.finish(PushNotificationIOS.FetchResult.NoData);
            }
            },
            senderID: '-----',

        permissions: {
            alert: true,
            badge: true,
            sound: true
        },

        popInitialNotification: true,
        requestPermissions: true,
    });
    });
}

export {
    configure,
};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...