Best way to check for data updates on webserver - ios

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

Related

Need advice on syncing data between iOS devices in one app

I built an in-house app for selling tickets and checking-in students to our High School dances. At the moment the app can scan a QR code with the student's information and add their name to either a "Sales" list or "Check In" list. Then the app can export these lists to a CSV file and we compile all the data.
App works perfectly as expected. NOW I want to be able to sync data between multiple devices so that every device will see an up to date Sales and Check in list. The check in list is most important because then our faculty chaperones can all see who has arrived to the dance in real time. I figured I would need to build a server to hold all the data as opposed to on the individual devices like I am doing now (CoreData). Can anyone please give me guidance or advice as to where to go from here? I am using Swift and developing for iOS 10.
I would just answer the general approach to tackle this problem since the implementations would largely be depending on many factors (what database technology is available, the platform of the server, etc.)
You are absolutely right, you need a server to hold the data. Technically speaking, it is a database that holding the data. Thus, you need a database running on your server (there are tons of selections here: Maria DB, SQL Server, Mongo DB, etc.).
Next, you need to build a web service on top of the database so that the iOS app can interact with the database (add/delete/update/read rows). Web service is a very common layer in full-stack application since you normally don't access the database directly.
Finally, you need to guard your web service with some sort of authentication. I.e. you don't want any random person out there to be able to access your web service without permission. There are many implementations out there to secure your web service and you should be able to google that easily.
Firebase might be the easiest solution. Its pretty simple to setup, and its pretty simple to set up data persistence when you go off line. I'm big on trying to stick with the built in Apple services, but Firebase is hard to beat for simple apps.
Take a look at CloudKit, or perhaps Firebase or Azure, as services that will provide a back end server for you, and give you a tested SDK to build against.

If I make a database on Realm, will it be accessible to my user without internet access?

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.

CouchDB and iOS

I need some help with a CouchDB iOS project.
I'm using Apache CouchDB Server and the couchbase-lite iOS Framework.
On my CouchDB I have a template document.
- CouchDB Server
- database
- template
- document 1
- document 2
- ...
My goal is to only synchronise my iPad with this template document to get the latest data which my application needs.
But when I enter some data on my iPad, I want that this data should be pushed only to couchBase Server.
How can I "tell" my application to synchronise only one file and not the entire database with my server and at the end how can I "tell" my application to only push the data that is input from user side ?
More importantly, Do I need two databases on my server? One for the template and a second one for user input data?
If YES, then I just need to know how I can only push my data.
Guidance needed. Thanks.
This is how I solve this:
I tend to add a 'last update' date to all my documents, and store this in a format that means they'll be sorted in time order (epoch or yyymmddhhmmss) both do.
Create a view that uses the update time as a date.
On your client, store the time since you last updated.
When you update, access the view with a startkey parameter set to the last update date.
You can then either use 'include-docs=true' to get the documents as you query the view.
I tend to use 'include-docs=false' though as it means when a lot of documents have been updated I transfer less data in a single query. I then just directly access each document id that the view returns.

Updating Sqlite from web server?

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

Which database can be used with Xcode and at the same time be populated through a website?

We are trying to create an iPhone application that will automatically receive data from a database. Which is a database that will work with Xcode. Our goal is that users can go to our website and input information. That data will be recorded to a database. Once the user downloads our app, the info should then be retrieved from the database and included in the app. We are wondering what database is suitable. It must be able to receive information from a website AND submit it to an application.
You're unlikely to find a iOS "aware" database that can automatically sync content over the internet.
However, you can of course obtain the data over the internet yourself and then insert it into the local database on the device, in which case the popular (and supported out of the box) SQLite would seem like an obvious choice.
As #Deepak also suggests, you could use Core Data which is a (sort-of, ish) ORM that can automatically use SQLite as it's underlying storage mechanism.
The solution that most people use in this case is to use an RDBMS like MySQL and build a web-service layer on top of the database for the entities that your iPhone app is interested in.
This way, when a user goes to the web-app, they can add the data that you allow them to add there, and later on they can access the same data from the iPhone app via the web-service layer also.
Couchbase's new iOS-Couchbase framework is in beta right now - all the functionality of Apache CouchDB on your favourite developer platform - at https://github.com/couchbaselabs/iOS-Couchbase. the iOS release is new but we're looking for it to go places!
Its awesome sync abilities would allow you to pull down any relevant content from your website via HTTP/JSON, or further formats using shows and lists if needed. Pushing data the other way is just as easy. Sync can be continuous, or on demand, bidirectional or one way.
Take a look at some of the Couch App frameworks (not for iOS but for your website)
http://techzone.couchbase.com/community/articles/couchdb/recipes
http://www.mail-archive.com/user#couchdb.apache.org/msg13928.html lots of comments on this thread
A+
Dave

Resources