i have tried multiple ways of setting device id variable once can used in other functions without requiring monaca callback. code not work:
function getdevid(){ monaca.getdeviceid(function(id){ return id; }); }
nor this:
var devid = monaca.getdeviceid(function(id){return id;});
so basically, how can set device id variable repeated use throughout app?
update: based on comment of possible duplicate asynch calls, went , analyzed , found correct. although not technically duplicate post, answer within post asynch workflow. solution issue can resolved way:
var devid = ''; document.addeventlistener ("deviceready", ondeviceready, false); function ondeviceready() { monaca.getdeviceid(function(id){ devid = id; }); }
i able use devid anywhere needed post load.
using deviceready
event listener, did, sure best approach, remember remove event listener when done. nevertheless, if using onsen ui, can use ons.ready()
, waits dom initialized. fired couple of ms after deviceready
, save code , have same result.
Comments
Post a Comment