I am developing an app where i need to sync data between several devices with the main datastore being a central server.
So one instance of app on a device will get new data, send it to server, i then need to send this data to the other devices.
Issue i have is, how best or what is the standard way to trigger the data download?
1) Have each device poll the server every x time to make sure its data is up to date?
2) Have a separate thread constantly waiting for new data and when the server receives new data it pushes it out to the devices?
3) When the server receives new data it sends out push notifications which when the devices receives this, it causes the app to sync with the new data?
4) Something i ain't thought about
I know all three will potentially 'work' but i wondered if there is a standard architecture / method to doing what i want to achieve.
::Edit::
The data needs to be fairly 'instant' if i poll it then i'll have to poll it every 30 seconds max to achieve the sync rate i ideally want.
I can send the data to my server no problem at all, i can even download the data once i have the trigger to, its just the mechanism that triggers the download I'm unsure off.
I imagine that new data will be sent to the sever properly on an hourly basis.
Thanks
Related
I'm building an app that fetches data from a third party server and syncs some of that data to my own server. The data for all users will be aggregated on my server and the results will be displayed in the app. The whole data sync (3rd party server -> App -> My server) should be done at least once a day. The app is only for a limited group of users and will be distributed with an enterprise account.
I'd prefer it to sync the data in the background, so the results on my server are always up to date and do not depend on the single users to open the app. I figured I'd use setMinimumBackgroundFetchInterval with UIApplicationBackgroundFetchIntervalMinimum so the sync would be handled in performFetchWithCompletionHandler in my AppDelegate. Unfortunately it doesn't seem to be possible to set a fixed interval for the background fetch. So I can't control when the sync is done, since it partly depends on the way the app is used when and how often the background fetch is executed.
Is there a way to modify the background fetch so I could guarantee the daily sync?
Or is there any other way to execute a background task on a daily basis with which I could accomplish the above?
The only solution I could come up with is a usability nightmare with daily local notifications to remind the users to open up the app, so that the background fetch can "learn" when to execute. I know this sounds bad, but I do have to present a solution to our customer :/
I am developing an iOS app which needs to receive regular data from the server at specific period of time (every 5 seconds).
Apple gives developers some choices for background working.
I convinced that Background Fetch is the proper method for my problem.
But when I tested it I got confused.
Background Fetch has many issues with my requirements:
It does not fetch data at period you defined when declared it:
application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
I tried this and this:
application.setMinimumBackgroundFetchInterval(5). But no guarantee
that your app will fetch data at this interval.
When the screen is off, your app will not make any fetch until the
phone is unlocked again.
I wonder if there is a way that let my app receives real time data (or at least every 5 seconds).
Note: I read about remote notifications and I do not guarantee that I can execute it now, So I am searching for other solutions.
Thanks
There is no solution to this problem until writing this answer.
If I need a real time notification then I must use Push Notification.
There is no way to check for server data every period of time from the app only, I can send a Remote Notification when new data available on server to wake up the app and let it connect to the server.
I'm developing an enterprise iOS app in Swift that needs to pull a list of items from our API and display them in a table view.
The list may change a few times a day but our system won't notify us when the data changes.
Instead, the app will need to poll regularly, say every two hours, to get the latest data and refresh the list. I have implemented the API call using NSURLSession directly.
My question is, what is a safe and efficient way to set up a polling mechanism? What if there are additional API services that must be polled, perhaps on different intervals?
Since you are developing an enterprise app and don't need app store approval you can 'misuse' one of the existing background modes, such as VoIP to periodically poll your data.
My suggestion, however, is to implement some code on another server that can poll the API and send a push notification to the devices when there is new data. This will be simpler to implement in the iOS app and more efficient in terms of battery life and data traffic. It also won't require the user to restart your app after device resets.
You can also easily use the same server to check additional data sources in the future.
An efficient polling mechanism can be implemented via NSTimer(s).
You can have multiple NSTimers fetching data from different locations and working on different dispatch queues.
Then, when you fetch new data, you can broadcast a local notification with the new objects (which is similar to Core Data model).
Your app would be able to access the retrieved data from anywhere.
If you only need to use the data in one location, you could use a delegate or a block-ish callback model.
I've got 3 devices and 1 application.
I make some changes on 1 device (collect milk from my cows). What is the best way server to tell other applications, that I've made this changes to reload data?
You can use the integrated iCloud feature allowing synchronization for CoreData managed objects. There are also some libraries using third party Cloud services like https://github.com/nothirst/TICoreDataSync
Push notifications could be an option. Once your server receives some changes it will issue the sync notification to all other devices which will initiate the sync.
Another option is where every device will periodically check, let’s say every 5 minutes, if any server changes available, and if so, then initiate the sync.
i'm writing an app that manage a sqlite database, and i have write a web server, i want the user register in my web server with username and password, i already know how make a request from ios app to server and receive the response, but i want enable also the synchronization of the sqlite database to other device, i now that with core data i can use iCloud synchronization, but for now i prefer use sqlite, and find a way to synchronize it, for example i want create this:
make a change in the sqlite in the iPhone app;
the app send this change to the server for that user;
then the server have to send this update to other device connected at that user;
and now i can't go over, how the server can send this change to the other device? the device has to be always listen to the server? or there is a way to send this update directly to some device and handle it? like an apple push notification?
EDIT: if it's possible use an apple push notification to do this, i doesn't want alert with text sound and badge the user, but send a "silent notification" it's possible?
As a high-level there are a few different ways to approach this, all of which have pros and cons. Two name two examples you can do a polling method, active push or a hybrid approach.
Polling: at some pre-determined interval the app tries to "phone home" and send the delta db changes up to the server. Here you know that your server will be expecting X number of responses in any given interval so you can appropriately gauge your load.
Active Push: The user decides when they want those changes to be transmitted to the server by hitting a "Sync" button. This allows the user to only push data back up to the server when they know there's a change but an over zealous user may make a change, upload, make a change, upload, etc instead of queueing up a bunch of changes and sending them all at once. This may create frequently unneeded server calls.
Hybrid: You setup a polling schedule within the app AND give the user the ability to Sync at-will in the event there is a critical change that needs to be made ASAP.
Regarding the listener side of the equation you face a similar challenge conceptually. If the original user makes 20 changes and presses Sync 20 times do you bombard the second user's device 20 times as well or do you queue those changes up and send them down every 5 minutes (as an example)? Unless you have both devices paired to each other or are connected to the same network AND visible to each other via your app you're going to need to leverage that back-end server. Push notifications can be very useful in this manner but there is extra development and setup overhead to take into account to properly implement them.
To boil this all down I would recommend laying out what YOU want your syncing model to look like before you start marching down a path.