So, I might be mistaken about how Meteor works under the hood, but is it possible to create a Cordova app which works without requiring internet connection ever? The ideal case would be that the assets including templates, js, css and images get bundled with the apk and no mobile-server needs to be configured.
In case the first scenario is not possible, maybe it is possible to cache everything and have the phone use the stored data when going offline. Connect once and then have the same experience when going offline.
Im using ground:db for my data, which works great. Just wondering about everything else. Appcache doesn’t seem to pull up images…
Yep. When you go to BUILD your app… There are many, many settings.
So you can do a normal build, intended for say a linux 64 bit server, which would run NodeJS and a MongoDB instance at some point…
When you build for Android / iOS, you specify mobile-server=https://www…com
So, if you do mobile-server=127.0.0.1 or localhost, I would assume it looks at itself.
Now, your database would have to change a little bit, to use localstorage mongo or something, which I’ve seen packages for. You’ll have to do some Googling and research but that should get you started.
There is a special “resources” folder for mobile apps that you can put images in I think. I don’t remember the details though. I’m not sure if it’s in the Meteor docs actually, it might be a Cordova thing.
I’ve been wondering if localstorage (ground:db) really is safe for storing data (and not just caching). I mean it’s just like a disposable cookie isn’t it? Or does Cordova treat it differently maybe?
The data is not a problem. I’ve confirmed that ground:db works as required for my app. Only part I need help with is storing all the assets locally. I just want to compile an apk and send that to someone who doesnt need to connect to my server.
Ah interesting. What about referring to them like src="/images/logo.png" though? Then you could have the same link for mobile and web, and not have to remember weird ports. Does that not work?
Oh yeah that works as well actually. I thought in cases where you have routes like this: /in/too/deep/ that you would need the absolute path from the start.
I don’t understand why you want to do that. The :12560 may change over time, since this is a random id Meteor uses, and it might change once you do another build. However, images in the public folder are always available and packaged with the app. Meteor itself cares about pointing the app to the right port (like 12560), all you have to do is use absolute links and omit the public folder: /images/my.image.png This will work just fine.
If you won’t provide a server via --mobile-server, your app will complain on the console that it can’t reach a server backend. But unless you don’t actually need one (since you don’t want to use methods or save something in Mongo), this should just work.
I don’t think it’s possible to run a full-fledged server on the device anyways. The local server on your device is used for starting up the client code and for serving static assets (like those in the /public folder). It also handles Hot Code Push. But if you don’t require a backend, this would be just what you need.
We have been using a offline versie of a Meteor Cordova app sinds June 2015, in combo with GroundDB and all assets in the resource folder. We access the images (an odd 150 items) like previously mentioned by Herteby (src="/images/logo.png"). All resources are bundled in the App (is 40MB plus)
We run do have a server running online just in case we need to update data and the client has a working internet connection. The app is a geo caching game where users are running round in a internet dead zone.
So instead we now pick a port from a predetermined range (12000-13000), calculated based on the appId, a unique identifier that is part of every Meteor project.