-
Notifications
You must be signed in to change notification settings - Fork 400
Closed
Description
Hi,
I am using ionic and want to save events to the native calendar.
Firstly, can this be done with your plugin? I'm under the assumption it can. if not, let me know and read no further.
I added your plugin on the command line with
ionic plugin add https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin.git
and then in my app call
var cal = window.plugins.calendar;
cal.createEventInteractively(title, location, notes, start, end, onSuccess, onError);
In the browser (which is the only place I can debug) window.plugins is undefined.
On the device it seems nothing happens.
Any idea what might be the issue?
Sorry to bother you, any help would be appreciated.
Ben
Activity
EddyVerbruggen commentedon Sep 7, 2014
Hi,
I don't use the Ionic CLI myself, but it as it's based on the Cordova CLI you could try this instead:
bentaly commentedon Sep 8, 2014
Thankyou so much, I will try this when I'm back, will let you know
bentaly commentedon Sep 10, 2014
Unfortunately I tried it and the error on the device is
'undefined' is not an object (evaluating 'window.plugins.calendar')
Do you think this is something that should work with ionic CLI?
Thanks
samedii commentedon Sep 11, 2014
Try waiting for 'deviceready'
document.addEventListener("deviceready", function() {
alert(window.plugins);
}, false);
bentaly commentedon Sep 11, 2014
I added that, it still came through as undefined. I already had the
$ionicPlatform.ready(function(){
});
Which shows the plugins as undefined too.
I'm pretty sure the above method handles the 'deviceready' event anyway.
Have you heard of anyone using this successfully with Ionic?
carchrae commentedon Sep 16, 2014
this person seems to have gotten it working: http://forum.ionicframework.com/t/eddy-verbruggens-calendar-plugin-with-ionic/3509
bentaly commentedon Sep 17, 2014
I have read that post, I dont really know what he's done differently, I know the plugin works, I have made a quick app and it works, i just dont know why it doesnt in my main app, there is not much structural difference, i will find out and post here.
carchrae commentedon Sep 17, 2014
Was the app that works in Ionic? I'm still trying to learn how/why ionic loads cordova plugins differently. Maybe it is something to do with the live reloading feature.
Have you looked at ng-cordova? This seemed like a good way to tie plugins into ionic. http://ionicframework.com/blog/ng-cordova/
bentaly commentedon Sep 17, 2014
It was an Ionic app, just a single controller, with a method to call the calendar, it works fine.
I have looked at ng-cordova, alas there is no calendar support
carchrae commentedon Sep 17, 2014
why not add it? i'm curious if that would work.
https://github.com/driftyco/ng-cordova/blob/master/src/plugins/datepicker.js
https://github.com/driftyco/ng-cordova/blob/d59a5881ae84ec1ebe92dd5d82ae3c3662c7dc54/src/plugins/module.js#L42
the main reason that adding it via ng-cordova might be better is that i think/hope the initialization code timing is handled for you.
i want to try wrapping another plugin that does not seem work either - same issue of window.plugins being undefined.
i did wonder if trying an older version of ionic might help - if there have been some regressions or api changes.
bentaly commentedon Sep 17, 2014
I imagine some issues on the timings would be added for you, I just dont think my app has the same issue.
Which plugin doesnt work for you?
have you tried making a simple seperate app to test just that functionality?
carchrae commentedon Sep 17, 2014
i've been trying to get http://ngcordova.com/docs/#BackgroundGeolocation working in ionic. and i'm wrong about wrapping it - it is already wrapped by ngCordova. i started off with a simple app first, but no luck. pretty annoying but I suspect it is something stupid i am doing or a version/regression issue. i'll dig into how these plugins are wrapped and perhaps that'll shed some light.
bentaly commentedon Sep 17, 2014
good luck - let me know how you get on, ill share any joy I have
carchrae commentedon Sep 17, 2014
i also tried using that plugin directly, without wrapping. in both cases the window.plugins code was undefined. i did find an issue where the plugin author said that another plugin had polluted the namespace (i think the push plugin - not sure) with code like this
if (!window.plugins) window.plugins = {}
so wonder if that is what might be happeningbentaly commentedon Sep 17, 2014
hmm, I'm not using any others apart from the default ionic ones, dont think that would be my issue
1 remaining item
EddyVerbruggen commentedon Sep 17, 2014
@bentaly cool, if you can, can you add an escaped version of the thing you had to add (for future reference)? Thx!
carchrae commentedon Sep 17, 2014
to what @EddyVerbruggen says - use backticks around the code sample. It is a shame that github does not handle that by default instead of dumping it.
EddyVerbruggen commentedon Sep 17, 2014
@carchrae +1 on that
bentaly commentedon Sep 18, 2014
haha didn't notice it cut it out -
I simply had to add
<script src="cordova.js"></script>
Which is 404 during development but the script seems to be injected to the root at runtime when on a device.
GSD-Automatisering commentedon Mar 12, 2015
I have a problem on IOS no errors no succes all methods have been recognized but no items in calendar does someone have an idea ?
bentaly commentedon Mar 12, 2015
is it in the:
$window.document.addEventListener('deviceready', function(){});
method?
GSD-Automatisering commentedon Mar 12, 2015
No its after Deviceready has been fired android version works well
ergencemir commentedon Aug 14, 2018
Hi @GSD-Automatisering ,
Did you resolve problem?
Junijoh commentedon Jan 5, 2019
Has anyone resolved the issue? I'm getting this error even though I load cordova.js at the beginning!
pointer commentedon Jan 22, 2019
Anyone??
thien1590 commentedon Apr 17, 2020
am here too soon :(
Marcel-Bich commentedon Jul 14, 2020
Have you tried window.onload in your index.html?
In some of my phonegap apps this helped out:
And of course the holy grail in phonegap or cordova development:
This fixes almost every incomprehensible bugs for me.
pointer commentedon Jul 14, 2020
pumpkin-zbh commentedon Jul 9, 2021
(window as any).cordova.plugins.[pluginName]