Friday 15 March 2013

Meteor Cordova: Cannot get camera plugin to work, Uncaught TypeError: Cannot read property 'getPicture' of undefined -



Meteor Cordova: Cannot get camera plugin to work, Uncaught TypeError: Cannot read property 'getPicture' of undefined -

i trying out meteor cordova photographic camera plugin , won't work, , have no thought i'm missing.

here did:

meteor create new project

added cordova photographic camera bundle meteor add together cordova:org.apache.cordova.camera@0.3.1

programmed default button on screen take image , append body. should utilize photographic camera built laptop computer when click button is: uncaught typeerror: cannot read property 'getpicture' of undefined

and when run app in iphone simulator command meteor run ios , click button popup error: failed because: no photographic camera available

this html , js file like:

main.html:

class="lang-html prettyprint-override"><head> <title>cameratest</title> </head> <body> <h1>welcome meteor!</h1> {{> hello}} </body> <template name="hello"> <button>click me</button> <p>you've pressed button {{counter}} times.</p> </template>

main.js:

class="lang-js prettyprint-override">if (meteor.isclient) { // counter starts @ 0 function onsuccess(imagedata) { var image = document.getelementbyid('myimage'); image.src = "data:image/jpeg;base64," + imagedata; $('body').append(image); } function onfail(message) { alert('failed because: ' + message); } session.setdefault("counter", 0); template.hello.helpers({ counter: function () { homecoming session.get("counter"); } }); template.hello.events({ 'click button': function () { navigator.camera.getpicture(onsuccess, onfail, { quality: 50, destinationtype: camera.destinationtype.data_url }); } }); }

this because cordova code must included closure, said on documentation. have in events functions. see bottom.

ps: can not test photographic camera on ios emulator, utilize real iphone instead.

meteor.startup(function () { // right way navigator.geolocation.getcurrentposition(success)); }); // not work navigator.geolocation.getcurrentposition(success));

your code become:

template.hello.events({ 'click button': function () { meteor.startup(function() { navigator.camera.getpicture(onsuccess, onfail, { quality: 50, destinationtype: camera.destinationtype.data_url }); }); } });

cordova meteor camera

No comments:

Post a Comment