I want to add a teaser slider to the start page of my mobile app. This slider should show up only once per device, so I want to store that the user has seen it locally. What’s the best-practice approach for storing persistent data on mobile devices? Would it be HTML5 local storage, or are there other options? Maybe even packages?
EDIT: Ideally, the solution should also survive any app updates from the app-store.
Localstorage should be fine, but you could also use the file api but I guess that would be overkill, although perhaps the safest in terms of app update survival.
Just saw on Caniuse that Mobile Safari only supports localStorage since iOS 8: http://caniuse.com/#search=localstorage If that’s correct, it won’t work on iOS 7. Would not be good if the user couldn’t get rid of the intro teaser due to this issue on older iOS devices.
Hold on, is your mobile app a cordova app? In that case you’ll be bundling your own webview component and if the cordova version provides you the api, you should be good to go. The same goes for the file api which is not supported by iOS 7 either.
Thanks for your quick reply. What do you mean by that statement exactly - I always thought that Cordova would use the default WebView components? Unless you exchange them explicitly, like Crosswalk does.
@oliverlloyd@norBu Thanks for your tips! As I see it, localForage seems to fit well for my use case, but gound:db is also very interesting if you also want to sync data with the server (which is not required here, or even counter-productive). But it’s good to know, I will definitely use this, too, for other purposes!
The only thing I am still wondering is if the localForage data really survives an app update, and how it behaves on iOS7 devices. Internally, it uses many different approaches, but I found no info which one would work in mobile scenarios.
EDIT: I just saw on Github that the localForage package hasn’t been updated for 2 years. It seems as if raix is not really developing it further, its version is on 0.0.0.
@waldgeist: I think local storage is probably the way to go. Not sure how important iOS 7 support is for your app, but the version of Cordova we upgraded to for Meteor 1.3 requires iOS 8 or higher, so that might be another consideration.
It looks like it’s not up to date because the latest version is in a different branch but the default is still set to master on the repo. I think Martijn is right though, local storage would be the simplest solution.
Installing app-preferences gives me the following error while building.
Errors executing Cordova commands:
While preparing Cordova project for platform Android:
Error: Cannot find module 'cordova'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Context.requireCordovaModule
I installed it with meteor add cordova:cordova:cordova-plugin-app-preferences@0.7.7.
@npolet Hi im facing a similar issue while trying to add this plugin to my project…what were your steps if you finally figured it out?
here is my error log
`Started proxy.
=> Started MongoDB.
% Failed to install ‘cordova-plugin-app-preferences’:Error: Cannot find module 'cordova’
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Context.requireCordovaModule (/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/hooks/Context.js:77:12)
at module.exports (/Users/zehijeanjacquesthibaut/Desktop/TRIZ_DIGITAL/WEBAPPS_MOBILE_APPS/NSIA/AgenceNumerique/.meteor/local/cordova-build/plugins/cordova-plugin-app-preferences/bin/lib/android.js:11:13)
at module.exports (/Users/zehijeanjacquesthibaut/Desktop/TRIZ_DIGITAL/WEBAPPS_MOBILE_APPS/NSIA/AgenceNumerique/.meteor/local/cordova-build/plugins/cordova-plugin-app-preferences/bin/after_plugin_install.js:9:37)
at runScriptViaModuleLoader (/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/hooks/HooksRunner.js:167:18)
at runScript (/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/hooks/HooksRunner.js:145:16)
at /Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/hooks/HooksRunner.js:130:20
at _fulfilled (/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/q/q.js:787:54)
at self.promiseDispatch.done (/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch (/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/q/q.js:749:13)
at /Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/q/q.js:810:14
at flush (/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:458:13)
=> Errors executing Cordova commands:
While adding plugin https://github.com/apla/me.apla.cordova.app-preferences.git#60e0c1bdcf9129ba347a1fadbac7cb6eaa092e64 to Cordova project:
Error: Cannot find module 'cordova’
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Context.requireCordovaModule
(/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/hooks/Context.js:77:12)
at module.exports
(/Users/zehijeanjacquesthibaut/Desktop/TRIZ_DIGITAL/WEBAPPS_MOBILE_APPS/NSIA/AgenceNumerique/.meteor/local/cordova-build/plugins/cordova-plugin-app-preferences/bin/lib/android.js:11:13)
at module.exports
(/Users/zehijeanjacquesthibaut/Desktop/TRIZ_DIGITAL/WEBAPPS_MOBILE_APPS/NSIA/AgenceNumerique/.meteor/local/cordova-build/plugins/cordova-plugin-app-preferences/bin/after_plugin_install.js:9:37)
at runScriptViaModuleLoader
(/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/hooks/HooksRunner.js:167:18)
at runScript
(/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/hooks/HooksRunner.js:145:16)
at
/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/hooks/HooksRunner.js:130:20
at _fulfilled
(/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/q/q.js:787:54)
at self.promiseDispatch.done
(/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/q/q.js:816:30)
at Promise.promise.promiseDispatch
(/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/q/q.js:749:13)
at
/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/q/q.js:810:14
at flush
(/Users/zehijeanjacquesthibaut/.meteor/packages/meteor-tool/.1.3.4_1.1ff5caj++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:458:13)