My App has a database file in its NSBundle. I want to get update database file from internet whenever new database file is available. and this should happen before app displays data from the database file.
Here is the logic i am trying to use. i don’t know if it makes sense or is there a better way to do it. an example will be awesome
if (file is available in the Documents Directory)
{
if( check if internet is available )
{
1. get file from network
2. store it in Documents Directory
if ( compare contents of the old & new file)
{
delete downloaded file
} else {
move or delete old file & rename new file ( so that the new file's data can be accessed )
}
} else {
use old file in Documents Directory
}
} else {
copy file from bundle to Documents Directory
}
Ideally you should have a timestamp or version number for the copy of the DB you have on the phone, and transmit that to the server. Then have the server only send a new copy if there is a newer version. Saves the user a lot of data charges.