Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mobile application data management

My question surrounds around one single point - data management in mobile application. I have created a mobile application where data comes from server. The data includes both text and images. Following are the steps I am doing for this :

First launch :
1. Get server data.
2. Save server data in Sqlite database.
3. Show Sqlite data.

Next launches :
1. Show Sqlite data.
2. Get server data in background.
3. Delete previous Sqlite data.
4. Save new server data in Sqlite database.
5. Show Sqlite data.

I have couple of questions on these steps :
1. Is this the right approach ? Other way could be showing data every time from server but that would not display the data on screen immediately (depending on internet speed).
2. I also thought of comparing the Sqlite data with the new server data. But faced a big challenge. The new server data might have new records or deleted records. Also, I could not find an appropriate approach to compare each database field with JSON data.
So what is the best approach to compare local Sqlite data with new server data ?
3. Each time I delete the Sqlite data and insert new data and then refresh the screen (which has a UITableView), it blinks for a second which is obvious. How to avoid this issue if steps 3, 4, 5 are followed ?
4. How should I proceed with data update in case I come back on the screen each time or when the application becomes active ? I am very aware of NSOperationQueues or using GCD for that matter. But what if I am crazy and go back and forth to screen again and again. There will be a number of NSOperations in the queue.

like image 409
Nitish Avatar asked Oct 07 '15 10:10

Nitish


1 Answers

It's a challenge to synchronise server data, I've done that before, and if you can spend time on it I'd say it's the best solution.

You may need creation and modification dates on both server and local objects, to compare them - this will let you decide which objects to add, update and delete. If the server sends you only the recently updated objects you can save a lot of traffic and improve performance (but deleted objects will be harder to detect).

If the data is only changed in the server it's easier, when the app can change the data too it becomes more complicated (but it seems that it's not your case). It also depends on how complex the database is, of course.

If you don't want to invest some time in doing this, just fetching all data everytime works too, even if it is not ideal! Instead of showing the old data and blinking it, you can just make the user wait 2-3 seconds when entering, while you get the new data. Or instead you can fetch the data only when starting the app, and so when you get to that view controller it will be ready already.

It's a complex problem that everyone faces at some point, so I'm curious to see what other people will suggest :)

like image 105
Tiago Lira Avatar answered Oct 01 '22 07:10

Tiago Lira