首页 > 解决方案 > 世博会每周通知在 Android 上

问题描述

我坚持尝试让我的世博会应用程序每周发送推送通知。在文档中,我读到我应该使用 WeeklyTriggerInput 接口作为我的触发器对象,但是当我尝试这样做时,我得到“无法安排通知。触发器类型:Android 不支持日历。” 错误。我也无法从 expo-notifications 导入 WeeklyTriggerInput 接口。这是我的代码:

const notificationParams: Notifications.NotificationRequestInput = {
            content: {
                title: 'Just title',
                body: 'Lorem ipsum',
            },
            trigger: {
                hour: 13,
                minute: 10,
                repeats: true,
                weekday: 1,
            },
        };
        try {
            const notificationId = await Notifications.scheduleNotificationAsync(
                notificationParams
            );
        } catch (err) {
            console.log(err);
        }

标签: react-nativeexpo

解决方案


通过遵循文档示例,这个片段对我有用:

        const id = await Notifications.scheduleNotificationAsync({
            content: {
                title: "Dia de planejar sua alimentação! ",
                body: 'Utilize uma de nossas receitas, crie suas próprias, experimente novas combinações ou veja a sugestão de um nutricionista.',
            },
            trigger: {
                repeats: true,
                weekday: 1, //Sunday
                hour: 8,
                minute: 0
            },
        });

推荐阅读