简体   繁体   中英

Synchronising in app settings with web server

I'm using InAppSettingKit to hold my application's settings. Some setting items are related to web server and they have to be saved in web server. How can I synchronise them and guarantee that they are identical?

Thanks in advance.

It doesn't appear that InAppSettingKit has any built-in support for client/server interaction, so you'll need to implement your own custom synchronization system.

Your question touches on a very broad topic with more than a few possible solutions with varying complexity, so I'll just explain how I'd do it if I were in your situation.

  1. CLIENT-SIDE

First, I'd integrate something like AFNetworking to simplify the process of saving and retrieval of data to/from the server. This will allow you to easily 'POST' your settings to the server and 'GET' them when you wish to retrieve them. AFNetworking is incredibly powerful, well-documented and free. You can learn more here:

http://www.afnetworking.com/

Whenever a user makes a change, use AFNetworking's methods to POST that change to a script residing on your server that saves it. When you wish to retrieve it, perform a GET operation. You'll need to generate some sort of unique key in the app to reference each user. If you use a login system of any sort in your app, you can tie it to that. You'll probably need to do the latter if you expect users to want to retrieve these settings from multiple devices.

You'll also need to decide upon a policy on how to handle conflicts. If the locally-saved settings differ from what you pull from the server, what do you do? What fallback do you use if your user is not able to access the network?

The usual solution is to just take whatever is more recent (meaning you'll need to store a timestamp for updates) - and this is probably most appropriate for simple needs - but the logic may differ depending on your needs.

  1. SERVER-SIDE

You will need a server-side component to handle saving these changes to the server. This could be a Node.js, Ruby, PHP, etc. script that takes the input sent to it by the server and saves it either in a database or file somewhere. This, too, is a broad topic and really depends on what your programming background is on the server-side.

Note: You should consider the security needs of such a setup, although this could be minimal if the settings being saved aren't at all sensitive. Otherwise, you will need to take appropriate measures to secure the data (SSL/TLS, salting/hashing passwords, etc).

  1. DO YOU NEED THIS?

You specifically mentioned "web server" in your question, so I assumed that you have your own server and are comfortable writing code for it (or willing to learn how). This is how I write my own client/server code and it has many advantages, but could be overkill for your needs if all you're doing is saving some settings.

With iOS 8 Apple introduced a simplified iCloud system called CloudKit. It ties everything to the user's iCloud account and is designed to be simple to set up. If all you're doing is syncing some simple settings you could use CloudKit's key/value storage to handle that for you.

There are some downsides to CloudKit. The stored data is opaque (ie. you won't be able to access it from a web app or an Android app, for instance), is limited to iOS 8 and newer and may cost you a nominal amount if your app is very, very popular. For simple settings synchronization, though, this may be wholly appropriate to your needs.

CloudKit pricing (probably free to you):

https://developer.apple.com/icloud/documentation/cloudkit-storage/

WWDC videos about CloudKit:

https://developer.apple.com/videos/wwdc/2014/?id=208

https://developer.apple.com/videos/wwdc/2014/?id=231

CloudKit design guide:

https://developer.apple.com/library/ios/documentation/General/Conceptual/iCloudDesignGuide/Chapters/Introduction.html

CloudKit framework reference:

https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CloudKit_Framework_Reference/index.html

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM