wmcmahan / react-native-calendar-events Goto Github PK
View Code? Open in Web Editor NEW📆 React Native Module for iOS and Android Calendar Events
License: MIT License
📆 React Native Module for iOS and Android Calendar Events
License: MIT License
That is definitely a must have
It would be awesome if through this library we could add a remote calendar subscription (.ics file for instance).
What do you think about it?
Hi,
I was receiving an error when deleting an event in Android using the removeEvent() call.
I fixed it by passing null instead of selection in the second param to cr.delete, in CalendarEvents.java:
Old
String selection = "((" + CalendarContract.Events.DELETED + " != 1))";
int rows = cr.delete(uri, selection, null);
Fixed
int rows = cr.delete(uri, null, null);
Please review to include in a later release. I found this solution by googling - I am not an expert on Android calendars.
Hi,
I have been trying for a while to get this module to work in React Native and every time I run
RNCalendarEvents.authorizationStatus() .then(status => { // handle status }) .catch(error => { // handle error });
I get the error that 'undefined is not an object'
on Android Nougat, events that are added to the calendar show as birthdays
When calling RNCalendarEvents.removeEvent('F7A090EC-115E-4AD2-BD6E-439936FC2C75')
I get this error:
Exception '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]' was thrown while invoking removeEvent on target RNCalendarEvents with params (
"F7A090EC-115E-4AD2-BD6E-439936FC2C75"
)
Any thoughts?
Hi! I've found that it's impossible to remove event with recurrence.
Also, I can't update recurrence status to none for existing event (the second one maybe is not an issue, I've just tried to hack someway to remove existing recurrence events);
Hi
I'm using a simulator running iOS 10.2 (iPhone6). When RNCalendarEvents.authorizeEventsStore() is run the application closes and produces no errors.. when i check authorized status is shows as undetermined.
using the code from the readme
RNCalendarEvents.authorizeEventStore()
.then(status => {
// handle status
})
.catch(error => {
// handle error
});
Hello,
I'm having a little issue hard to debug.
React native calendar events works quite well on my dev env but once the app deployed through hockey app, the add to calendar does not work on iOS and leaves me with an error.
Find below a screenshot of the error:
Like that for the moment I did not find a way to be able to reproduce this error and access it on my dev env, so I'm looking for your help.
Would you have any idea why this happens ?
Thanks,
Xavier
Hi,
So the calendar event creation works perfectly in the iOS simulator, but has not worked once when installing to a physical device.
Any ideas?
I commented on #23, but I'm seeing a native error when trying to make a call to RNCalendarEvents.saveEvent
on Android. cc @lilach
Here's the stack trace, although it probably isn't very insightful.
Error: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference
at createErrorFromErrorData (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7099:11)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7062:35
at MessageQueue.__invokeCallback (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7442:10)
at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7294:8
at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7213:1)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7293:1)
at onmessage (http://localhost:8081/debuggerWorker.js:44:56)
Hi,
Getting an error on Android when setting allDay: false. The event is getting created but on the emulator the app quits, on the device the app doesn't quit but the error stacktrace is the same.
Android Genymotion emulator (Android 7.0) / Device OnePlus (Android 6.0.1)
RN 0.44.0
Calendar-Events 1.3.6
error stacktrace from android studio:
05-18 11:57:13.411 21570-21580/? E/ContentValues: Cannot cast value for allDay to a Integer: false
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Number
at android.content.ContentValues.getAsInteger(ContentValues.java:288)
at com.android.providers.calendar.CalendarProvider2.fixAllDayTime(CalendarProvider2.java:1530)
at com.android.providers.calendar.CalendarProvider2.insertInTransaction(CalendarProvider2.java:2192)
at com.android.providers.calendar.SQLiteContentProvider.insert(SQLiteContentProvider.java:99)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:263)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:163)
at android.os.Binder.execTransact(Binder.java:453)
05-18 11:57:13.412 21570-21580/? E/ContentValues: Cannot cast value for allDay to a Integer: false
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Number
at android.content.ContentValues.getAsInteger(ContentValues.java:288)
at com.android.providers.calendar.CalendarProvider2.updateEventRawTimesLocked(CalendarProvider2.java:3024)
at com.android.providers.calendar.CalendarProvider2.insertInTransaction(CalendarProvider2.java:2202)
at com.android.providers.calendar.SQLiteContentProvider.insert(SQLiteContentProvider.java:99)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:263)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:163)
at android.os.Binder.execTransact(Binder.java:453)
05-18 11:57:13.413 21570-21580/? E/ContentValues: Cannot cast value for allDay to a Integer: false
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Number
at android.content.ContentValues.getAsInteger(ContentValues.java:288)
at com.android.providers.calendar.CalendarInstancesHelper.updateInstancesLocked(CalendarInstancesHelper.java:698)
at com.android.providers.calendar.CalendarProvider2.insertInTransaction(CalendarProvider2.java:2203)
at com.android.providers.calendar.SQLiteContentProvider.insert(SQLiteContentProvider.java:99)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:263)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:163)
at android.os.Binder.execTransact(Binder.java:453)
Using promises instead of events to return the ID after calendar event creation would make for a much nicer interface.
I checked the documentation, but I didn't see a way to save and event (https://github.com/wmcmahan/react-native-calendar-events#saveevent) with an alert set (for ex. "2 hours before the event") and/or travel time (ex. "5 minutes").
Does this package support passing parameters for that?
Hi, thank you for the component.
Is there a way to show the user an alert modal confirming that the event has been added successfully to the calendar? And also a modal to say to the user, "Do you want to see the event added in the the caledar?" Yes/No
Thank you in advance
Hi,
This is my addCalendarEvent function
addCalendarEvent(){
console.log("add Calendar Event");
RNCalendarEvents.authorizeEventStore()
.then(status => {
console.log(status);
})
.catch(error => {
console.log(error);
});
RNCalendarEvents.authorizationStatus()
.then(status => {
//status = denied, restricted, authorized or undetermined
console.log("Calendar authorizationStatus:", status);
})
.catch(error => {
console.log("Calendar authorizationError:", error);
});
startDate = new Date("13 Jan 2017, 02:02 AM");
endDate = new Date(Date.parse(startDate) + 3600000);
RNCalendarEvents.saveEvent('test', {
location: 'location',
notes: 'notes',
description: 'notes',
startDate: startDate.toISOString(),
endDate: endDate.toISOString(),
allDay: false,
recurrence: 'none',
alarms: [{
date: -30 // or absolute date - iOS Only
}]
})
.then(id => {
console.log("Calendar event id:", id);
})
.catch(error => {
console.log("Calendar add event error:", error);
});
startDate = '2017-01-12T00:00:00.000Z',
endDate = '2017-01-13T23:59:59.000Z',
RNCalendarEvents.fetchAllEvents(startDate, endDate)
.then(events => {
console.log("events found", events);
})
.catch(error => {
console.log("error finding events", error)
});
}
In the console I get the following results:
As you can see the event id is 0 from the saveEvent Promise and no event is added as can be seen from the fetchAllEvents result also.
Can someone help me understand what's going wrong?
RN 0.39.2
Testing on Android 6 device
I'm on iOS and in my app I authorize the calendar store, but I cannot set events until I restart the app. It still acts like the calendar system has not been authorized when I try to add events directly after authorization. Is there some way I'm supposed to reinitialize the calendar object so that it can properly see the new settings?
Cheers
I am adding event with RNCalendarEvents.saveEvent, but its not setting on my calendar. I am using iOS simulator to test my code.
Got BAD_ACCESS
exception on iOS 8 when invoking fetchAllEvents
#0 0x00000001006cb684 in -[RNCalendarEvents serializeCalendarEvents:] at RNCalendarEvents.m:331
NSDictionary *emptyCalendarEvent = @{
_title: @"",
_location: @"",
_startDate: @"",
_endDate: @"",
_allDay: @NO,
_notes: @"",
_url: @"",
_alarms: @[], <- Thread 1: EXC_BAD_ACCESS (code = 1, address=0x0)
_recurrence: @""
};
Change NSArray
literal notation into [NSArray array]
fixes this. I don't know why this happens because array literals notation is supported since Apple LLVM 4.0.
NSDictionary *emptyCalendarEvent = @{
_title: @"",
_location: @"",
_startDate: @"",
_endDate: @"",
_allDay: @NO,
_notes: @"",
_url: @"",
- _alarms: @[],
+ _alarms: [NSArray array],
_recurrence: @""
};
React Native version: 0.39.0
Platform: iOS 8.2 (12D508)
Operating System: MacOS 10.12 (16C67)
I have setup the application and followed, and double checked every step.
When hitting the button to add an event, nothing happens, no calendar, no event, no error, nothing.
function checkPermissions(event, reminder) {
RNCalendarEvents.authorizeEventStore(({status}) => {
if(status.toLowerCase() === 'authorized') {
return _addToCalendar(event, reminder);
}
return AlertIOS.alert(
'Unable to create event',
'We need permissiont o access your calendar in order to create an event.'
);
});
}
function _addToCalendar(event, reminder) {
const calDate = reminder ? moment(event.sortDate).subtract(1, 'month') : event.sortDate;
const reminderDate = moment(calDate).hour(8).minute(0).toISOString();
const eventDate = moment(calDate).hour(0).minute(0).toISOString();
if(reminder) {
RNCalendarEvents.saveEvent(`Reminder: enter ${event.title}`, {
location: 'location',
notes: 'notes',
startDate: reminderDate,
endDate: reminderDate,
});
} else {
RNCalendarEvents.saveEvent('title', {
location: event.location,
notes: 'notes',
startDate: eventDate,
endDate: eventDate,
alarms: [{
date: -60
}]
});
}
}
What have I missed that makes this work.
Thanks
On my macbookpro I have my calendars setup to sync to a remote caldav server, and I can see a whole list of full year's events on the calendar upon successfully setup. And then I wrote the following code in my react-native dev project:
componentDidMount() {
RNCalendarEvents.fetchAllEvents('2016-01-01T00:00:00.000Z',
'2016-12-30T23:00:00.000Z',
events => {
console.log(events)
}
)
}
But I only see 4 items which are synced with my friends birthday found in the email. Is there anyway I can do with this issue?
Hello I was wondering if there are any plans to add a method to fetch an event by its ID. I have a use case where I want to be able to query an event to see if it exists by the ID as I won't know if the current date stored on my device is correct and can't use it in the fetch-all-in-date-range method. My app will have support for multiple devices, offline mode, and synching via webserver, so I'm interested in being able to check if a single event is already set up on the device, and if so, does the date in iOS calendar match what is stored in my App's databse.
I see that there is a method in the Calendar API for this
https://developer.apple.com/reference/eventkit/ekeventstore/1507490-event
I'd take a whack at it myself but I zero experience in that language.
For now I can do a fetchAll using a huge daterange and then loop through every event to see if the iOS event that I'm looking for exists and then whether it's set for the correct date.
Cheers and thanks for putting this package together
A simple gif of the package working would be great.
We need it.
Using React-Native v0.33.0
After running import RNCalendarEvents from 'react-native-calendar-events';
, RNCalendarEvents is undefined.
For single event, I save to device without any problems.
But when I try to save many events in the array, it fails.
console complains: TypeError: Cannot read property 'alert' of undefined
Here is my Code:
saveCalendar() {
console.log('RAC', this.props.eventops);
const myCalendar = this.props.eventops;
myCalendar.forEach(cal => {
//console.log('THE CAL', cal);
let evtDate = new Date(cal.EventDate);
evtDate = evtDate.toISOString();
console.log('THE CAL', evtDate);
let evtEndDate = new Date(cal.EventEndDate);
evtEndDate = evtEndDate.toISOString();
console.log('THE CAL', evtEndDate);
RNCalendarEvents.saveEvent(`Abu Dhabi - ${cal.Title}`, {
location: `${cal.Location}`,
notes: `${cal.Text}`,
startDate: `${evtDate}`,
endDate: `${evtEndDate}`
})
.then(id => {
AlertIOS.alert('Announcement', 'Add the event Successfully!', console.log(id));
})
.catch(error => {
console.log(error);
}, setTimeout(() => {
this.popupDialog.closeDialog();
}, 50));
});
}
Hey @wmcmahan Facing this issue in Android, RN 0.40, Android 6.0, as per my understanding, if you do not specify a calendar id, the default device calendar is used, but unfortunately, i'm getting this error. Any ideas?
Worked like a charm in IOS, and btw Great work on this module. 👍
RNCalendarEvents.saveEvent('title', { location: 'location', notes: 'notes', startDate: '2017-05-20T19:26:00.000Z', endDate: '2017-05-20T20:26:00.000Z', alarms: [{ date: -1 // or absolute date - iOS Only }], recurrence: 'daily' })
This will create a recurring event from 19:26 to 20:26 daily. And it goes on forever.
In your RNCalendarEvent.m, you set the end date to be nil,
if ([validFrequencyTypes containsObject:frequency]) { rule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:[self frequencyMatchingName:frequency] interval:1 end:nil]; }
which means the recurring event goes on forever.
Can you update this part to allow user to set an end date.
After installing this module, the app compiles fine but crashes instantly using the iOS 8.2 simulator (anything less than iOS9, I believe, and before loading RN) unless CoreFoundation.framework
is linked with Optional
status. Due to an unhelpful error message, it took a lengthy git bisect to track down sometime after the fact, so it seems—unless this is symptomatic of some other issue—that CoreFoundation.framework
(Status: Optional) could perhaps be included in the installation instructions. Unless, of course, there's a more effective/correct solution.
Error message:
dyld: Symbol not found: ___NSArray0__
Referenced from: /Users/rreusser/Library/Developer/CoreSimulator/Devices/.../data/Containers/Bundle/Application/.../MyApp.app/MyApp
Expected in: /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 8.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
in /Users/rreusser/Library/Developer/CoreSimulator/Devices/.../data/Containers/Bundle/Application/.../MyApp.app/MyApp
const {NativeAppEventEmitter} = React;
this.eventEmitter = NativeAppEventEmitter.addListener('calendarEventsChanged', () => {
RNCalendarEvents.saveEvent(this.props.data.post_title, {
location: `PVJ ${this.props.data.custom_fields.tenant.post_title}`,
notes: 'notes',
startDate: date.format("YYYY-MM-DDTHH:mm:ss.sssZ"),
endDate: date.format("YYYY-MM-DDTHH:mm:ss.sssZ")
}, events => {
console.log("RNCalendarEvents saveEvent:", events)
});
});
i keep getting error "addListener of undefined", did i do wrong?
Hey, I have a problem with the allday attributes.
If I save an event from Monday 0:00 to Tuesday 23:59 with the "allday" attribute, the event is only registered for Monday. Tuesday is ignored -this works well on IOS-.
I don't know if it's the way android calendar works but if I remove the allday attribute on my default HTC calendar the Monday event is automatically flagged "allday" and the Tuesday is filled from 0:00 to 23:59.
Now if I create an event from Monday 0:00 to Wednesday 0:00 without "allday" attribute i've got my Monday and Tuesday flagged as "allday" event.
Anyone knows if it's the right way to save "allday" events on android ? or my htc default calendar is pretty clever and this would fail on all other android devices ?
anyway, thanks for the good work.
Hi! Thanks a lot for your library.
I've double checked this behavior in at least two android devices.
Expected: fetchAll
should fetch all events in all calendars
Actual: fetchAll
is not fetching the recurrent events in all calendars
It fetches correctly all events but recurring ones.
Is there something am I missing or is this an actual bug?
Thanks a lot!
Fran
hi, i'm quite new on installing nativeModules, so could you please explain this section
"Then add RNCalendarEvents, as well as EventKit.framework to project libraries.
For iOS 8 compatibility, you may need to link your project with CoreFoundation.framework (status = Optional) under Link Binary With Libraries on the Build Phases page of your project settings."
into a steps?
Thank You
Hi,
On Android I can list all my device calendars, even the "Contacts" calendar. But on iOS the FindCalendars returns an empty array. I tried on different iOS devices configured with iCloud and Google calendars but the list is always empty.
My code:
RNCalendarEvents.authorizationStatus()
.then(status => {
RNCalendarEvents.findCalendars()
.then(calendars => {
console.log('CALENDARS:', calendars);
this.setState({
calendars,
});
if (calendars.length > 0){
this._selectCalendar(calendars);
} else {
Alert.alert(this.props.title, 'No calendars defined.')
}
})
.catch(error => {
console.log('ERROR!', error);
});
})
.catch(error => {
console.log('ERROR!', error);
});
Hey all,
I am trying to add events to the user calendar via my React Native app.
But I am getting an error saying No calendar has been set after calling RNCalendarEvents.saveEvent (), and when trying to request calendar authorization with RNCalendarEvents.authorizeEventStore()
my app crashes.
Regards,
Mehdi
Hi,
I'm getting this error:
Error getting default calendar for new events: Error Domain=EKCADErrorDomain Code=1013 "(null)"
2017-03-10 17:58:17.542 [info][tid:com.facebook.react.JavaScript] errorError: No calendar has been set.
Already linked the libraries on XCode.
Can I solve this problem ?
Thanks.
"react-native-calendar-events": "1.3.6"
"react-native": "0.41.2"
I'm using Android 6.0.1 device and this code
RNCalendarEvents.findCalendars().then(calendars => {// handle calendars});
returns Array with Objects structured:
[{
allowsModifications:false,
id:"1",
isPrimary:false,
source:"[email protected]",
title:"Contacts",
},{
allowsModifications:false,
id:"2",
isPrimary:false,
source:"[email protected]",
title:"Holidays in Ukraine"
},...]
If I write calendarId (I tried all id's) when save event my app shutting down and not save event.
If I not write it, the event appears as birthday (like in #54)
Code that saves events:
RNCalendarEvents.saveEvent(`title`, {
location: `location`,
notes: `location`,
startDate: ISOFormattedDate,
endDate: ISOFormattedDate
}).then(res=>console.log(res)).catch(error => {
console.log(error);
});
in IOS works well. Any suggestions about how to save event not as birthday in default calendar?
Also this events dissapears from default calendar after some time.
Hey all. Really useful library, and I've loved it so far.
One thing I've found that was a little annoying at first was having to format the start and end date strings when saving an event. I've made a decision to avoid moment.js as I really don't do a lot of work with dates in my app, and I didn't want the extra code size. I also found out the hard way that react-native-calendar-events requires strings for start and end because there was an NPE when I supplied a Date for start and end.
I ended up having to write a custom formatter for this, and it looks like you guys parse this string into a native Date object afterward anyway. I would love to supply a javascript Date object or even an epoch long to represent dates for saveEvent
When trying to run a test I receive the Error:
"Cannot find module 'react-native-calendar-events'"
I believe the reason for this error is there is no main file specified in package.json and the normal require resolver does not know how to handle index.ios.js vs index.android.js.
I think this is more of a feature request, but I would love the ability to select the calendar to save my calendar events to. I hope to have more time to possibly contribute to this repo, but something I would like to see in the next version or so! You guys rock though and thanks for the library!
As an enhancement can you add IS_PRIMARY as an available field for android when fetching calendars. This would allow us to add events to the user's primary calendar.
Thanks,
For me in Android CalendarEvents.java didn't added to Native Modules. So var CalendarEvents = NativeModules.CalendarEvents
call in React library returns undefined.
Set up properly.
Version:
react-native-cli: 2.0.1
react-native: 0.41.2
In the readme, it says we need
npm install react-native-calendar-events
to install the library, in fact we need to say
npm install react-native-calendar-events --save
I am new to react native, and this costs me some time to figure it out. Can you update ReadMe so that it won't confuse other people
My application stop working when I try to add new event into calendar.
Here call example:
RNCalendarEvents.saveEvent('Test', {
location: 'New York, United States',
startTime: '2017-03-29T10:30:00.000Z',
endTime: '2017-03-29T11:30:00.000Z',
description: 'Test description'
});
Here the exception description from logcat:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference
at com.calendarevents.CalendarEvents.addEvent(CalendarEvents.java:308)
at com.calendarevents.CalendarEvents$2.run(CalendarEvents.java:510)
at java.lang.Thread.run(Thread.java:818)
Library version: 1.3.6
React Native: 0.42
Sorry if this a naive question, First time developing react-native app. In android I would normally declare permission required in manifest, <uses-permission android:name="android.permission.READ_CALENDAR" />
, So even with this I would still need to use authorizeEventStore
to get secondary permission?, or is it only necessary if the user denied it initially and at run time you want to offer them to change their mind?
Hi,
Got the code to write an event in the calendar and the calendar event does show an alert of 30 min before but I did not get any alert message. Am I missing something? On Android device the same code gives a nice alert notification.
My first time dabbling with iOS so don't know if this is how it is in simulator.
RN 0.40.0
iPhone6 iOS 10.1
Hello
First, thanks for building such a react-native code and share it.
Will it find calendars and thus events of Google Calendar and MS Exchange calendar if the device has them configured?
Cheers!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.