React-Native代码可以在不导入平台模块的情况下工作,为什么?

时间:2019-04-02 18:19:26

标签: react-native react-native-android react-native-native-module

我刚刚将此代码添加到了home/index.js文件中

if (Platform.OS === 'android') {
    Expo.Notifications.createChannelAndroidAsync('chat-messages', {
        name: 'Chat messages',
        sound: true,
        vibrate: [0, 250, 250, 250],
        priority: 'max',
    });
    Expo.Notifications.createChannelAndroidAsync('reminders', {
        name: 'Reminders',
        sound: true,
        vibrate: [0, 250, 250, 250],
        priority: 'max',
    });
}

但是在发布到博览会之后。我意识到我没有导入Platform模块。

为什么创建了通知通道并且没有抛出错误?

我在项目中没有全局变量。

1 个答案:

答案 0 :(得分:0)

createChannelAndroidAsync仅适用于android,因此无需检查平台,react-native会照顾它