i got existing js project, sole programmer has been working on 6 months , left without explaining. anyway written in ionic, , have read , tested, tool building cordova + angular applications. anyway got app deployed on phone fine, cordova command line , can server ionic serve, familiar other node servers. problem developing. i'm used app running on pc, checking stuff dev tools, see when , resource being accessed , more. app working normal on mobile when getting pc can't past login screen error "cordova not defined". checking code more heavily depended on cordova. can solve this? here sample code project run error on login:
var dir = window.resolvelocalfilesystemurl(cordova.file.datadirectory, function(dir) { dir.getdirectory("build/", {create:true}, function(adir) { fs.builds = adir; }, fs.fserror); dir.getdirectory("assets/", {create:true}, function(adir) { fs.assets = adir; app.asseturl = fs.assets.tourl(); document.dispatchevent(new customevent("fs-ready", {})); }, fs.fserror); }, fs.fserror); thanks in advance
the mobile application mvc (model-view-controller) contains 2 parts:
- native code (android - java/ obj-c/swift - ios) - model
- ionic(gui) + angular + cordova - view + controller
by cordova interfaces gui can talk native part.
when try run www root in browser (apache or similar), tells cordova not defined since browser hasn't cordova sources (it stored in mobile assets).
your application starts on mobile when cordova ready doesn't happen in browser.
anyways run project in browser(chrome ...) since use angular, controllers talk 1st services. create folder data json files simulate responses mobile native angular , instead call cordova api, call $http.get json file.
$ionicplatform.ready(function() { if (ionic.platform.isandroid() ) { $rootscope.imandroid = true; } else if (ionic.platform.isios() ) { $rootscope.imios = true; } else{ $rootscope.imbrowser = true; } } in service:
// load json data async way promise app.factory('items', ['$http', function($http) { return { getjson: function(url) { var itemsjson = $http.get(url).then(function(response) { return response.data; }); return itemsjson; } } } ]); so example looks like:
self.login = function(){ if ($rootscope.imbrowser === true) { // in browser call json file return items.getjson('data/loginresponse.json'); } if ( (ionic.platform.isandroid() || ionic.platform.isios() )) { // on mobile call cordova return cordovaservice.login(); } };
Comments
Post a Comment