Synchronize data between server and iOS application - ios

How to synchronize new data added in the database of server or middle ware to the devices installed our app?

Typically what's done is the app makes a call to the server to refresh the data when it's opened or a refresh has been requested.
If you want the user to know they're missing out on new data, you should use push notifications to let them know the number of new updates.

if you are supporting iOS7 and above you can do background data sync , for more info refer to similar question at Background sync in iOS7

Related

How to wait until cloud kit data is being synced with core data in swift in iOS13

I developed core data based app and implemented iCloud sync feature after it was introduced in iOS 13.
I enabled iCloud kit, used NSPersistentCloudKitContainer instead of NSPersistentContainer and added several lines of code to sync core data with iCloud.
Sync works fine. The problem is that when I uninstall app and reinstall app, it doesn't fetch iCloud data at first time.
I have to restart app or open another screens to let Core Data to be synced with iCloud.
Is there anyway I can check if core data is being synced with iCloud or wait until it finishes syncing?
Thanks.
There is no API exposed to get the completion handler on sync of all
CKRecord's to NSManagedObject's.
Also the update is working using a background silent notification so we can expect any change anytime. So its good to not having completion handler
What's next
You can create one attribute to check the sync time, just like a date when last sync happened to local record and check the lastModificationDate (By default CKRecord has this property) of the same record in iCloud.
So everytime when you launch the app check for all the records manually if any update is required, then wait for notification of update and keep on checking the sync status
Note: Be careful this may lead to delay your launch process if from any other device user is very active and new records are getting inserted or modified.
Currently, there is no API provided for iCloud sync completion. What you can do is
You can initialize NSPersistentCloudKitContainer and call it's loadPersistentStores() at the start of the app. This will buy you enough time and your data will be available for your internal screens.
You can also listen for remote changes in your local store and update your UI accordingly as mentioned in this Apple doc: https://developer.apple.com/documentation/coredata/consuming_relevant_store_changes
I have to restart app or open another screens to let Core Data to be
synced with iCloud.
To solve this I'm using a notification observer for NSManagedObjectContextObjectsDidChange event.
When reinstalled app is first opened, it shows empty screen and after some time, when data is synced, the notification is triggered and the page is reloaded with the data.
However I also couldn't find any way to wait and show loading message while data is being synced.

IOS Real time updates won't trigger if app is in background state

I set up websocket support in my hapi server using nes
Tried it on android and so far the realtime updates is still working even in background state.
The problem is with IOS, realtime update won't trigger when your app is in the background state. How can i make this work
iOS only allows your app to keep running in the background in some specific cases. Keeping the WebSocket connection is not one of them. In order to achieve this realtime update, your server needs to provide an API which allows the app to fetch the new data, and your app needs to register a background task and do the fetch. For more detail, you can check the link here.

How to periodically call to a webservice even when the app is in background?

I want to do some server pulling in my iOS app. It something like this. When m app installed it should start a background service to check weather is there any new data available since the last updated date. If yeas my app should start a local push notification. How can I do this? I want to know how I can periodically check is there any new data available in server even when my app is in background.
Please help me.
Thanks
On iOS 7 and above, you have Background App Refresh. It's covered in the documentation under Fetching Small Amounts of Content Opportunistically. You can read more about it under Use Background App Refresh.
One caveat is that the user can turn off Background App Refresh for your app.

ios - Bulding an app that have push notification appear on a specific time interval

I'm building my first application.
I'm making app where I'm doing some fetching from rss feed of web site and loading it to a TableView. What I want is next:
-to inform a user when new feed arrive, when my app is closed (user can set the time interval of update frequency in app settings page) - with Local Notification
I'm using NSURLSession for downloading data, storing it with Core Data, and want the Deployment Target to be iOS 7.1.
Just want to know is it possible and steps that I need to do to implement it correctly.
What you want is called Background Fetch. Background fetch can fetch data from your servers even when the app is not running.
Local notifications would be of no help here. Even when a local notification has been fired, user will have to click on it to fetch data.
Look it up. There is a pretty decent tutorial here.

How to run run a process frequently as a background service ios

I am working on ios app that used to read ticket data as a barcode scanner. It needs to upload data frequently to a web server, Like two or three times a day. I have done the sync function. I just wanted to run the function when the app is run in background.
This is not possible on iOS, Apple is not allowing any kind of background service on iOS.
The options you are left with is setting your apps background mode to fetch and implement application:performFetchWithCompletionHandler:. But it is totally up to ios if and when this method is called.
You could misuse one of the other background modes to keep your app open in the background, but Apple might reject your app for doing so. Also user might complain about you app draining battery.
What kind of data is that you need that you have to update it two to three times a day? I would say the when the app is opened by the user would be a good time to update, because this is when the user is expecting new data.
If you need to inform the user about some data changes you should be pull it in the app but a server should send a push notification to inform the user that there is new data.

Resources