-1

I know the answer is not enough to explain in a single or two paragraphs, and there might not be tutorials available also as it needs internet services. But I just need some advice and suggestions so that I can move further in designing my app in a proper way.

My application is a service based application, it works perfectly when internet is connected. However as per new requirements I need to support offline behaviour also. Hence it would be like to keep a local database, and fetch everything from server first time, Later when internet is not connected, if user uploads some data then it will be stored in local database and automatically synchronised when internet available.

I don't have a clear idea how to do it. I guess my application may cause memory warnings because of inappropriate data handling and it may also increase the internet traffic if do not handle services in a proper manner.

I know there may be variety of answers as it is a conceptual question but I am not looking for a tutorial but just some proper guidance to do my research and get to have a clear idea how to do it.

Thanks everyone in advance. Happy coding.

Rameswar Prasad
  • 1,281
  • 16
  • 34

1 Answers1

0

2 things you need to know about,

Core Data

Core Data is a framework provided by Apple allowing you to load and save data. I suggest you use CoreData to save any data when the app is online.

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.

Reachability

Reachability is a class also provided by Apple to check whether the internet is on or not. See this answer for better understanding of how to use it

What I'd do:

1) Create 2 entities in the xcdatamodeld. One for your server data, second for the user's data.

2) Use the Reachability class to check the internet connection. If the connection is on, upload user's saved data and download server's data and save it. If the connection is off, display the latest data saved in the xcdatamodeld

Community
  • 1
  • 1
Ty Lertwichaiworawit
  • 2,930
  • 2
  • 20
  • 41
  • In my experience you still have to write a lot of boilerplate code with Core Data. – John Topley Aug 28 '14 at 09:28
  • @JohnTopley So if it were you, what would you use? Im curious – Ty Lertwichaiworawit Aug 28 '14 at 09:30
  • 4
    The answer, as often, is "it depends". Which is why I voted to close the question because it's too broad. I might use Core Data, maybe in combination with a higher-level framework such as RestKit. Or I might use FMDB. I know that Vesper uses FMDB and Node.js running on Azure to achieve essentially what this question is asking. http://inessential.com/vespersyncdiary is an interesting read about the design considerations around adding sync support to Vesper. – John Topley Aug 28 '14 at 09:35
  • @JohnTopley thanks for the info John, Ill keep that in mind the next time i need to use CoreData – Ty Lertwichaiworawit Aug 28 '14 at 09:39
  • No problem. There's lots of interesting writing about the subject here http://www.objc.io/issue-4/ and here http://www.objc.io/issue-10/ – John Topley Aug 28 '14 at 09:44
  • @JohnTopley I admit it, and already have mentioned it is a too broad, but can you tell where we can discuss this concept further in stack overflow community or a discussion forum later where I can clarify more about the subject. I want to know what are different possible ways to do this. Looking forward to your reply. – Rameswar Prasad Aug 28 '14 at 09:54
  • @Rameswar http://programmers.stackexchange.com/ ? – John Topley Aug 28 '14 at 09:56
  • @Ty_ Thanks. I have already used "Reachability" class. I will delve into "Core data". Thank you for the direction. – Rameswar Prasad Aug 28 '14 at 09:57
  • @JohnTopley thanks john for the link. I will come back at free time to discuss more about it. – Rameswar Prasad Aug 28 '14 at 09:58
  • @Rameswar You're welcome and good luck! – John Topley Aug 28 '14 at 10:04