-
Notifications
You must be signed in to change notification settings - Fork 400
Closed
Description
Using the demo code in a loop, I can't create more than one(or two, sometimes) event. The second call to createEvent will issue a 'No calendar has been set." error(even though findEKCalendar has just printed "Calendar: Calendar" to the log). Trying more than 2, in general, results in nothing happening.
However, if I take the code in createEventWithOptions in Calendar.m out from behind the 'runInBackground' call,
/* [self.commandDelegate runInBackground: ^{ */
everything works perfectly, although a tad slower, obviously.
XCode 7.0.1
iOS 9.0.2
Cordova 5.3.1
"cordova-plugin-calendar": "4.4.3"
Activity
ants-house commentedon Feb 10, 2016
Hey,
I'm discovering the same issue on iOS... Creating one event works perfectly, creating more than one event ends up in freezing or just doin' nothing. The same issue is for deleting events. Deleting one event works, deleting more than one doesn't work. On Android everything works as expected, on iOS everything is broken. I also restricted creating events to max. 64.
Maybe someone can help... I really need this so a workaround would be better than nothing.
Regards
EddyVerbruggen commentedon Feb 10, 2016
Are you waiting for the first
createEvent
to return or are you just hammering the native code 64 times in a row?ants-house commentedon Feb 10, 2016
Well I'm running through the for loop which always calls the native code. I think it's not waiting for the first createEvent to finish. Is there a possibility to wait for it?
tcowin commentedon Feb 10, 2016
I did commit to fix this, but it’s not going to happen today. The problem is that it is not multithread safe. If you don’t run it in the background, then it will work fine in your context. You’d need to edit (hack cough, cough) src/ios/Calendar.m and comment out the loop that puts it in the background, like so:
in the function createEventWithOptions (lines 470 and 557 in the latest):
/* [self.commandDelegate runInBackground: ^{ */
/* }];*/
Thanks,
Tom
ants-house commentedon Feb 10, 2016
Got it :)! Calling the function recursively works really good!
EddyVerbruggen commentedon Feb 10, 2016
@aaronprojects That's the best way to do it as JS-Native calls to the Cordova bridge are async it's always best to wait for the callback to return.
Btw, by not running the Calendar in the background and hammering it in a loop you will block the UI which degrades performance.
tcowin commentedon Feb 10, 2016
Of course - that’s just a temporary workaround.
Javascript is asynchronous for speed, right? So if you suggest you have to wait until every call completes whether or not you need the result, you’re losing the advantage that it gives you…
Actually this is just another way of working around the problem of it not being able to handle two addEvent calls in a row. It will still run O(N). I’d still think the best solution would be that it’s made multithread safe? I’ll try to figure it out.
EddyVerbruggen commentedon Feb 10, 2016
@tcowin I know you did it is as a workaround / experiment, I'm just making sure others understand why it's implemented like it is.
I never created the plugin with threadsafeness in mind (that's why I added recurring events for making many events), but I can imagine there are valid cases for it. I don't know if whether or not the native calendar can be stressed that much so I'd rather not hammer it too much. Please consider that when trying to make it threadsafe and test it in a loop of 100+ invocations.
tcowin commentedon Feb 10, 2016
Sure - will do. The app that uses this for us syncs a set of distinct events for the user's conference itinerary, so the recurring is not an option. I'll look at what it would take to enable concurrent calls to addEvent, but maybe adding a call like addEvents, where you'd send in an array of events that the Objective C then iterates through might even be more performant.
BhargavaNandan commentedon Jul 31, 2017
Hi this plugin is compatible with ios and android do we have any plugin to add calendar events for windows 10 devices using cordova
unsama commentedon Dec 5, 2017
**
**
here's my calendar events how i add in loop to post in database