【问题标题】:No channel id passed, notifications may not work. react-native-push-notifications没有通过频道 ID,通知可能不起作用。反应原生推送通知
【发布时间】:2026-02-04 11:40:01
【问题描述】:

错误:WARN 未传递频道 ID,通知可能不起作用。

[LOG] createChannel 返回“假”

如何传递频道ID?

这是我的代码:

export const LocalNotification = () => {
    PushNotification.localNotification({
        autoCancel: true,
        bigText:
          'This is local notification demo in React Native app. Only shown, when expanded.',
        subText: 'Local Notification Demo',
        title: 'Local Notification Title',
        message: 'Expand me to see more',
        vibrate: true,
        vibration: 300,
        playSound: true,
        soundName: 'default',
        actions: '["Yes", "No"]'
    })
}

const startFunction = async () => {
  
  PushNotification.createChannel(
  {
    channelId: "channel-id-1",
    channelName: "My channel",
    channelDescription: "A channel to categorise your notifications",
    playSound: false, 
    soundName: "default",
    importance: Importance.HIGH, 
    vibrate: true, 
  },
  (created) => console.log(`createChannel returned '${created}'`) 
  );

  LocalNotification();

}

【问题讨论】:

    标签: react-native react-native-push-notification


    【解决方案1】:

    PushNotification.createChannel( { 频道 ID:“频道 ID-1”, channelName: "我的频道", channelDescription: "用于分类通知的频道", 播放声音:假, 声音名称:“默认”,

              vibrate: true, 
            },
            (created) => console.log(`createChannel returned '${created}'`) 
            );
       
        PushNotification.localNotification({
            channelId : "channel-id-1",// this is where you need to add local notification
            autoCancel: true,
            bigText:
              'This is local notification demo in React Native app. Only shown, when expanded.',
            subText: 'Local Notification Demo',
            title: 'Local Notification Title',
            message: 'Expand me to see more',
            vibrate: true,
            vibration: 300,
            playSound: true,
            soundName: 'default',
            actions: '["Yes", "No"]'
        })
    

    【讨论】:

      最近更新 更多