Crash on Calendar API with createEventAsync function
See original GitHub issueEnvironment
Environment: OS: Linux 4.13 Node: 8.1.2 Yarn: Not Found npm: 4.6.1 Watchman: Not Found Xcode: N/A Android Studio: Not Found
Packages: (wanted => installed) expo: 27.0.0 => 27.0.0 react: 16.3.1 => 16.3.1 react-native: https://github.com/expo/react-native/archive/sdk-27.0.0.tar.gz => 0.55.2
Steps to Reproduce
- Create a new calendar and get its id with
const calId = await Calendar.createCalendarAsync(myCalendar)
- This is interpreted as an integer
- Use this id to add an event to your newly created calendar :
const eventId = await Calendar.createEventAsync(calId, myEvent)
When the function is called, expo just crashes, not falling into my catch and not letting me know what is wrong. After some hours of searching, I tried a different approach which works.
- If first create my calendar, get the id back
- I reload my calendar list using getCalendarsAsync()
- And then I find the calendar I just created in the list using a find and a ‘==’ comparison (not ‘===’ as id in the calendar object is a string and id returned by createCalendarAsync is an integer)
- Finaly I use the id from the calendar object to create my event and it works just fine
So I think, the first thing is that the app crashes if you give an integer as calendarId in createEventAsync, you have to give the id as a string instead. The second thing is that this should be consistent between the id returned by createCalendarAsync et the id expected for createEventAsync whether it is a string or an integer.
I hope this will help some people who fall on the same problem than me.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Hi @SleepyFanjo , Thanks a lot for sharing your code. It helped me to understand Expo.Calendar better.
I think the problem with your code might be that createEventAsync is expecting calendarId to be a string but createCalendarAsync returns a number.
calling
await Calendar.createEventAsync(calendarId.toString(), event)
helped me get over this step.Hi @SleepyFanjo - sorry for the super slow followup here. We’ll try and look into this as soon as we can. Thanks for the report and the repro case.