首页 > 解决方案 > null 不是对象(评估“RNCalendarEvents.authorizationStatus”)

问题描述

我正在尝试使用此包“从'react-native-calendar-events'导入RNCalendarEvents;”在日历电话中放置一个事件 但我有这个错误“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)
                });
        }
    }

标签: react-nativecalendar

解决方案


我想我在安装模块时没有向 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');
    }
}

推荐阅读