null不是对象(正在评估'RNCalendarEvents.authorizationStatus')

时间:2019-11-02 16:00:41

标签: react-native calendar

我正在尝试使用“从'react-native-calendar-events'导入RNCalendarEvents“程序包在Calendar手机中放置一个事件;  但是我有这个错误“ null不是一个对象(正在评估'RNCalendarEvents.authorizationStatus')”

import RNCalendarEvents from 'react-native-calendar-events
onPressAdd() {
        if (Platform.OS === 'ios') {
            RNCalendarEvents.authorizationStatus()
                .then(status => {
                    console.log(status)
                })
                .catch(error => {
                    console.log(error)
                });
        }
    }

1 个答案:

答案 0 :(得分:0)

我认为我在安装模块时没有向iOS android添加依赖项。

您尝试运行react-native link react-native-calendar-events

编辑

请删除该模块,然后尝试从头开始安装。

  1. npm install --save react-native-calendar-events
  2. react-native link react-native-calendar-events

用法

import RNCalendarEvents from 'react-native-calendar-events';
RNCalendarEvents.authorizationStatus()

如果这不可能,则由于它是先前制造的模块,因此可能不可用。

如果您要检查日历的权限,则可以用此模块替换它。

import {PermissionsAndroid} from 'react-native';
async function checkPermission() {
write_calender = await PermissionsAndroid.WRITE_CALENDAR
read_calender = await PermissionsAndroid.READ_CALENDAR
if (granted === PermissionsAndroid.check(write_calender) && 
    granted === PermissionsAndroid.check(read_calender)) {
      console.log('You can use the CALENDAR');
    } else {
      console.log('CALENDAR permission denied');
    }
}