使用react-native-fcm时不在ios设备中显示通知

时间:2018-08-08 10:39:22

标签: ios swift react-native react-native-fcm

我正在使用来自react-native-fcm来接收pushNotification并完成本文档中的所有配置(https://github.com/evollu/react-native-fcm)  在ios设备中,只能接收由console.log检查的通知和呼叫notificationListener,但不显示通知消息,甚至不会警告FCM。显示本地通知的presentLocalNotification仍然不显示通知

    async componentDidMount() {
        if (Platform.OS === 'ios') {
            try {
                const result = await FCM.requestPermissions({ badge: false, sound: true, alert: true });
            } catch (e) {
                console.error(e);
            }

            FCM.getFCMToken().then(token => {
                if (token !== undefined) {
                    // this.props.onChangeToken(token);
                } else {
                    console.log('TOKEN (getFCMToken)', 'null');
                }
            });

            // FCM.getAPNSToken().then(token => {
            //     this.props.onAPNToken(token);
            // });

            FCM.getInitialNotification().then(notif => {
                console.log('INITIAL NOTIFICATION', notif);
            });

            this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {

                console.log("  >> notificationListener: ", notif)

                if (notif.local_notification) return;
                FCM.presentLocalNotification({
                    body: 'tdtydt',
                    priority: "high",
                    title: 'notif.fcm.title',
                    sound: "default",
                    show_in_foreground: true,
                    local_notification: true,
                   icon: "ic_launcher",
                    status: "400"
                });

            });
            this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, token => {
                console.log('TOKEN (refreshUnsubscribe)', token);
                this.props.onChangeToken(token);
            });

            FCM.enableDirectChannel();
            this.channelConnectionListener = FCM.on(FCMEvent.DirectChannelConnectionChanged, (data) => {
                console.log(`direct channel connected${data}`);
            });
            setTimeout(() => {
                FCM.isDirectChannelEstablished().then(d => console.log('isDirectChannelEstablished', d));
            }, 500);
}

0 个答案:

没有答案