世博会推送通知未显示-Android上的本地通知需要标题

时间:2019-09-04 09:37:03

标签: javascript android react-native push-notification expo

我已经在由Expo管理的React Native应用中实现了Expo的Push Notifications(尚未弹出),但是该通知未显示在我的Android Oreo设备上。

应用启动时,我已经实现了以下代码:

let previousToken = await AsyncStorage.getItem('pushtoken');
console.log(previousToken);
if (previousToken) {
    return;
} else {
    let { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);

    if (status !== 'granted') {
        return;
    }

    let token = await Notifications.getExpoPushTokenAsync();
    console.log(token);
    await AsyncStorage.setItem('pushtoken', token);
    if (Platform.OS === 'android') {
      Notifications.createChannelAndroidAsync('test-channel', {
        name: 'Test Channel',
        sound: false,
      });
    }
}

Notifications.addListener((notification) => {
    Notifications.presentLocalNotificationAsync({
        title: notification.data.title,
        body: notification.data.body,
        android: {
            channelId: 'test-channel',
            color: '#FF0000',
        },
    });
});

我正在使用Expo的“推送通知”工具将通知发送到我的应用程序,并且收到了通知,但是通知从未显示在设备上。当我收到来自Expo的通知时,我也会收到此错误:

[未处理的承诺被拒绝:永久违反:Android上的本地通知需要标题] -invariant中的node_modules / invariant / browser.js:39:8 -_validateNotification中的node_modules / expo / build / Notifications / Notifications.js:68:18 -presentLocalNodeificationAsync $中的node_modules / expo / build / Notifications / Notifications.js:164:30 -tryCatch中的node_modules / regenerator-runtime / runtime.js:45:44 -调用中的node_modules / regenerator-runtime / runtime.js:271:30 -tryCatch中的node_modules / regenerator-runtime / runtime.js:45:44 -调用中的node_modules / regenerator-runtime / runtime.js:135:28 -node_modules / regenerator-runtime / runtime.js:170:17在 -tryCallTwo中的node_modules / promise / setimmediate / core.js:45:7 -doResolve中的node_modules / promise / setimmediate / core.js:200:23 -Promise中的node_modules / promise / setimmediate / core.js:66:12 -callInvokeWithMethodAndArg中的node_modules / regenerator-runtime / runtime.js:169:27 -入队的node_modules / regenerator-runtime / runtime.js:192:38 -异步中的node_modules / regenerator-runtime / runtime.js:216:8 -presentLocalNodeificationAsync中的node_modules / expo / build / Notifications / Notifications.js:110:15 * App.js:28:50英寸 -__emitToSubscription中的node_modules / fbemitter / lib / BaseEventEmitter.js:185:32 -发出时的node_modules / fbemitter / lib / BaseEventEmitter.js:166:42 -_emitNotification中的node_modules / expo / build / Notifications / Notifications.js:30:18 -发出时的node_modules / react-native / Libraries / vendor / emitter / EventEmitter.js:190:12 -__callFunction中的node_modules / react-native / Libraries / BatchedBridge / MessageQueue.js:366:47 -node_modules / react-native / Libraries / BatchedBridge / MessageQueue.js:106:26在 -__guard中的node_modules / react-native / Libraries / BatchedBridge / MessageQueue.js:314:10 -callFunctionReturnFlushedQueue中的node_modules / react-native / Libraries / BatchedBridge / MessageQueue.js:105:17 * [本地代码]:callFunctionReturnFlushedQueue中为空

* * *

我在做什么错?请帮忙!谢谢。

0 个答案:

没有答案