android - 世博会保存日历事件

标签 android calendar expo

我正在尝试在 Android 上的 Expo 应用程序中保存日历事件。这是一些代码:

const details = {
  endDate: "2018-05-16T20:00:00.000Z",
  location: "...",
  notes: "...",
  startDate: "2018-05-16T19:00:00.000Z",
  timeZone: "GMT-7",
  title: "...",
  url: "http://www..."
};

try {
  console.log('Adding Event');

  const eventId = await Calendar.createEventAsync(Calendar.DEFAULT, details);

  console.log("Event Id", id);
}
catch(error) {
  console.log('Error', error);
}

在这种情况下,将记录“添加事件”。但后来什么都没有。没有事件 ID 或错误。而且该事件没有显示在我的日历中。

这是通过 Android 上的 Expo 应用程序运行的。

日历项在 iOS 上完美保存。

我事先要求获得日历权限,所以我认为这不是问题所在。

这里可能出了什么问题?我该如何调试?

最佳答案

如文档中所述,获取默认日历的功能仅在 iOS 设备上可用:

Calendar.getDefaultCalendarAsync() iOS only. Gets an instance of the default calendar object. https://docs.expo.io/versions/latest/sdk/calendar/#calendargetdefaultcalendarasync

在 Android 上,您可以遍历 getCalendarsAsync 的结果,直到找到带有 isPrimary: true 的结果。像这样:

const calendars = await Calendar.getCalendarsAsync();
const calendar = calendars.find(({isPrimary})=>isPrimary);

关于android - 世博会保存日历事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50336625/

相关文章:

默认时区的Android解析时间

java - 插入命令上的 SQLite 外键不匹配

python - Python 中的日历 .ics 到 CSV

react-native - expo 安装开发依赖

ios - Expo ImagePicker 在 IOS Gallery 未打开时崩溃

Expo + React Navigation + Vercel : Deep Linking not working

java - 如何知道 fragment 何时变得不可见

android - 如何获取当前通话的电话号码

Java用时间戳计算时间

CalendarWidget 在 Plone 4.2.4 + PloneFormGen 上损坏