I am currently building an iPhone app that is using Core Data and sqlite databases where the user will be reading static information from the database throughout the app. I have the issue where we may update the information in the database but not want to do a full update of the app, just the database. Can someone please help me out with either a easy function or a tutorial of how to go to a website or server and download the file which will replace the database that we have already put into the app? I'm new in xcode and I`m doing my first app.... thanks for your help
I think what would be a good idea is for your website to publish the data that must be stored in sqllite over REST, possibly in JSON or XML format.
This blog post describes how you could do just that. I must say that its approach to retrieving the content from the webservice is kind of low-level but it'll get the job done. Maybe RestKit can help you take care of all the low-level networking/http stuff.
I assume you want the static data locally so you don't require a constant internet connection for your app to work. Another option is to request the static data from the web and persist it in a file (NSUserDefaults etc...). But, that depends on how complicated the static data is and whether you have to query into that data. If you need to issue queries on that static data, a DB is definitely better.
You can also do a combination where you download updated DB if available async while your app works. You could have a setting in user defaults which is the current static data DB. If updated, you switch the current setting and re-establish the DB connection under a lock.
Here's how to make an http request using iOS.
rest web services in iphone
If you're downloading db data, don't convert the NSData to a string like in that sample ...
Also, ASI-HTTP-Request is popular. Here's samples on how to download a file:
http://allseeing-i.com/ASIHTTPRequest/How-to-use
http://www.cocoadev.com/index.pl?NSUserDefaults
Related
Recently started with electron. Can any one please help me with the database selection. It seems like there is no straight forward choice for it.
Suggest a database for medium size project.
In Electron app, you can use the database of your choice :
https://github.com/louischatriot/nedb
https://github.com/pouchdb/pouchdb
http://lokijs.org
https://github.com/kripken/sql.js
https://github.com/pubkey/rxdb
https://github.com/amark/gun
https://github.com/typicode/lowdb
https://github.com/google/leveldb
According to your purpose, a single JSON file can be used as a database.
You can use CouchDB, which is the non-sql database, in that you can store data in JSON format, they have inbuilt sync functionality, that means, you just need to store data locally in HTML storage provider and CouchDB will automatically sync that with the server.
I am going to display list of cities and countries. I have to get it from server using web service. but city and country are not changed every time. so we don't need to call that web service every time. so we can store all the information locally. what is the best way to handle this situation?
Yes you are right we don't need to call web service every time. You can use coredata in this situation. Using coredata you can manage all data locally and retrive back from coredata.
Core Data is the best one to use for non-trivial data storage. It can reduce the memory overhead of your app, increase responsiveness, and save you from writing a lot of boilerplate code.
Refer this link : http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started
You can do this in several ways
you can use nsurl session caching
store data in local db (coredata or sqlite) http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started
For simple data you should use NSUserDefaults
use plist file http://www.theappcodeblog.com/?tag=ios-saving-data-to-plist-tutorial
http://code.tutsplus.com/tutorials/ios-sdk-working-with-nsuserdefaults--mobile-6039
please check the following also
storing data locally on the iphone
Store data locally IOS
There is some more option to locally
1. Using LocalDB - its little bit pain but not bad that much
2. Using XML file - you should have the method to retrieve the data.Its pretty easy
3. Using Plist - This is also very easy can done through few lines.
4. NSUserDefaults - This can be use only as few cases like User information, store tokens.
Got it!
I have an application which uses the data from web server. When you first launch the app, it downloads the data and then work with it. But what if the data on web site was changed. How can I know from the application that the data was changed, and if so, what data should I download?
My first idea was each time when you run the application to check the number of entries in the local database on your phone and the number of entries on web server, and if they are not equal, delete all data in local database and then download all data again. But I think that it will take more time than if the application just loads 5-10 needed records instead of all data.
The second idea was when the information on the site changes, website somehow has to inform the application to load some records. But I don’t know if it is possible to do(
Another idea was to compare the id of the last entry in the application database with last id on website. And if they are not equal download the information from the next id.
Are there any suggestions how can I accomplish this?
I am not sure that you have any database or web services but my suggestion is parsing data from the web with JSON or XML.
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSXMLParser_Class/
this class reference is will be clear for you.
Also in my opinion, if you are new in swift and want to choose easy way for this operation search for iOS package managers.
If you want to use a package manager for your project, e.g Pod
https://cocoapods.org/pods/Alamofire
would be a good startig point.
Alamofire is an HTTP networking library written in Swift.
Hope to helped you
I'm trying to build my first Swift app and I think Realm may be a good option for my database. This might be a totally stupid question, but will my users be able to access the data on my database without an internet connection? I'm fairly certain that the answer is yes, but I just want to make sure.
As a side note, I want the data to be stored on the users phone (not a server or anything like that)
Thanks for the help
Yep! Realm is a completely offline, local database solution. There's no online component, but if you do decide to, you can sync data from Realm online using third party cloud services like Parse (Or just literally copying the database file to Dropbox).
By default, all data saved with Realm is stored in a file called 'default.realm' in the Documents directory of your app, but you can easily explicitly set where you want the data to be saved.
I'm currently updating an app which I developed quite a long time ago. I'm wondering what's the best way to update the sqlite database via REST api.
I'm thinking about the following process:
When the user is opening the app the device will send the current database version (locally stored in a .plist) to a REST webservice.
The webservice compares the client version to the web version - if there is a new one available I would like to send the entire database to the client (no delta updates).
Now I'm thinking what's the better way to "send" the data to the client. Download a sqlite? Or create a JSON at the webservice (what means somehow overhead). The sqlite is currently about 100 kb.
Anyone an idea?
If
there is no user data to preserve and there won't be any in the future, e.g. if your database is completely static
it is safe to assume its size is not going to increase significantly
your database model hasn't changed and is highly unlikely to change in the future
you're 86% sure that you'll never again be requiring a proper api to a similar online database, featuring delta updates and a generic format like json
go ahead and transmit that replacement sqlite. Otherwise, do it properly!