我正在尝试使用“从'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)
});
}
}
答案 0 :(得分:0)
我认为我在安装模块时没有向iOS android添加依赖项。
您尝试运行react-native link react-native-calendar-events
请删除该模块,然后尝试从头开始安装。
npm install --save react-native-calendar-events
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');
}
}