Ionic 5: How to write to local JSON files? - json

I'm developing an Ionic-Angular mobile application that involves tracking user progress. While I'm familiar with how to read from locally defined JSON files (and render that data), I've been unable to find any solutions online to write/append to local JSON files.
Until I'm able to utilize something like Google Firebase, I'd like to be able to just store this data by writing to local JSON.
Is there any way I can do this or is a database the only solution?

I'm assuming this is a web application. There is no way you can access the file system of the user to persist the data.
Other options
Index DB (save the information locally to the user at the browser level). User can go to the mobile device settings and clear it if required.
Use a mock api if this is only during the local development purpose (Use json-server and watch the database json file. You can update the database json file and it will reflect)
If you are building a hybrid application using ionic, then use one of the cordova plugins available here.
Use an actual backend service which persists it in the database.

Related

Change Rate-Us URL remotely without updating the app Android

I want to use a Json file, when i click on a button to rate the app, the URL will be in a Json file Online, so i can any time change it without updating the app from the market.
Is there any example for that ?
You may want to check/use the Firebase Remote Config to define parameters in your app and update their values in the cloud, allowing you to modify the appearance and behavior of your app without distributing an app update.
Here's a Sample App Walkthrough from them on how to use the Firebase Remote Config.

PhoneGap store HTML Files on Device

I have to build an App for Windows Mobile and iOS. So I decided to create this with PhoneGap.
The app should only display HTML-Files.
These files are stored on a server and can change every day.
So I created already an API which delivers the files.
My solution would be:
In my PhoneGap-App I use AJAX to get the files (this is no problem and should already work...).
To the question:
How can I store the files on the device? Is this possible with PhoneGap?
The app have to work offline too (because of this I need to store the files)...
And if this is possible: It should sync only the differences (between device/app and server) --> keyword rsync??
Thank you for your help!
Emanuel :)
Have you checked here?
You can definitely store files locally on android platform.(I have already done that). However, I haven't done it on IOS.
So please investigate, if features I gave the link above, available for safari (IOS).
Synching only diff should be implemented on the server side and should be responsibility of your API.
Yes you can store files locally.
I would recommend the Phonegap File Transfer plugin for downloading files. It supports iOS and Windows phone 7 and 8 and can download and save the file locally. At the Cordova file plugin github you can see the paths where you can save the files for iOS, I haven't found a table for windows phone yet.
But I would not recommend you download the HTML files since they can be very big. You should dynamically create the mobile pages you need, since you would only need to download the displayed text and attributes for some HTML-tags.
The way you can do this is by having a server back-end where you can change the content of the pages. The plain HTML should then be saved in a database with a creation and modification timestamp(needed to check if you have the latest updates). You would then pull the data out of the database with your PHP and echo it as a JSON. Your app just has to make a AJAX-GET request to the server and save the data locally in a database. I would recommend the Cordova SQLite Storage plugin for the local database. Whenever a page is opened you should dynamically create a mobile page.
This way your app doesn't request huge amount of data from a server, which can be more appealing to your app users.

Where to store application data for webapp?

I have some data for a webapp that I would like to store on the server. What would be a good location to put those files?
I have a couple of static HTML pages that contain instance specific information. They need to survive a re-deploy of the webapp. They need to be editable by the server's administrator. They are included in other HTML pages using the html object tag.
I want to store preferences on the server, but cannot use a database. I am using JSP to write and read the preferences. There is no sensitive data in the preferences. Currently I am using the log directory. But obviously that is not a great choice.
I am using Tomcat. I thought of creating an appdata/myapp directory under the webapp directory. Is that good or bad?
If the server's administrator can also deploy the app, I would add the data file itself into the source control for the app, and deploy it all together. This way you get revision control of the data, and you get the ability to revert to known good data if the server fails.
If the administrator can't deploy the app, but can only edit the file, then you need plans to back up that file in the case that the server or server filesystem dies.
A third solution would be a hybrid: put the app in one source code repository. Put the data in a second source code repository. The administrator can edit the data and deploy the data. The developer can edit the app source code, and deploy the source code. This way, both are revision controlled, but you've separated responsibility for who maintains what.

unable to persist indexedDB after reinstallation

I am unable to persist indexedDB when I re-install the chrome app which is using it. While I'm able to persist data using the sync file system across re-installations.
Should I use the storage API to push the indexedDB data in an array and store it in a file?
Is there a "C language" like way in JS(while making chrome app) to save data using structs and file access? Something like data structures using JS.
Am I going all wrong? And the solution to this problem is rather simple and obvious.
All what you get for app is the app sandbox and resources also using in the app sandbox. Chrome delete the sandbox and it resources after app was removed. And it's true behavior then you create a sandbox.
You need any back-end/server-side storage to store use data and sync it then user reinstall the app.

How do I host JSON files on my website?

One of my iPhone apps uses JSON data to populate it's database. However, I'd like to make that process automatic by hosting the JSON file online. How do I do this?
example of the content I want to host:
[{"Name":"John","Value":22,"Colour":"brown","City":"Auckland"}
Well you just need a hosting, upload your file and point your app to that file thats it. Search for any free hosting on google, there are plenty of them.
You can store them as files on your HTTP server or generate them from database with any of server-side languages.