在expo中配置android设备的本地通知?

问题描述 投票:0回答:1

我对react-native相当陌生,还在学习。我正在尝试为一个android设备配置本地通知,但却无法使用。在尝试解决这个问题的时候,我了解到Permissions已经从expo中移出,android的Notifications需要创建一个单独的对象,声音和振动才能工作。其他网站上的例子似乎也不能用。也许有更新)。我已经尝试从新的 "expo-permissions "中导入 "Permissions",但还是不行。请帮助我!

这是我的代码。

import Notifications from 'expo';
import * as Permissions from 'expo-permissions';
async obtainNotificationPermission() {
        let permission = await Permissions.getAsync(Permissions.USER_FACING_NOTIFICATIONS)

        if (permission.status !== 'granted') {
            permission =await Permissions.askAsync(Permissions.USER_FACING_NOTIFICATION);
            console.log("Permission Status: "+permission);
            if (permission.status !== 'granted') {
                Alert.alert('Permission not granted to show notifications!')
            }
        }
        return permission;
    }

    async presentLocalNotification(date) {
        await this.obtainNotificationPermission();
        console.log("Permission Status: "+this.obtainNotificationPermission());
        Notifications.presentLocalNotificationAsync({
            title: 'Your Reservation',
            body: 'Reservation for '+ date + ' requested',
            ios: {
                sound: true
            },
            android: {
                sound: true,
                vibrate: true,
                color: '#512DA8'
            }
        });

    }
android react-native notifications expo uilocalnotification
1个回答
0
投票

而不是这一行

import Notifications from 'expo';

插入

import { Notifications } from 'expo';
© www.soinside.com 2019 - 2024. All rights reserved.