New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't createEvent* more than one event in loop #239
Comments
Hey,
Maybe someone can help... I really need this so a workaround would be better than nothing. Regards |
Are you waiting for the first |
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? |
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
|
Got it :)! Calling the function recursively works really good!
|
@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. |
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.
|
@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. |
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. |
Hi this plugin is compatible with ios and android do we have any plugin to add calendar events for windows 10 devices using cordova |
**
** |
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"
The text was updated successfully, but these errors were encountered: