J.D.
J.D.

Reputation: 103

Saving data outside iPhone

I have made an app with core data. but now, I thought, what if user loses or replaces their device. Let's say they get a new one and reinstalls the app.

What's the best and simple way to get the data I had before that was stored in his old device in core data.

Can you please give your thoughts about this?

Upvotes: 1

Views: 184

Answers (3)

Son of a Beach
Son of a Beach

Reputation: 1779

For a single device, and any replacment device (if broken or lost), just backing up to either iTunes or iCloud is enough. Then you can restore from that backup if/when necessary. This applies to any application data, not just CoreData.

You application could also include functionality to copy the CoreData persistent store file elsewhere, and then to load it up from elsewhere. This is usually just a single SQLite database file and is straightforward to copy between devices. Eg, copy it to the 'Documents' directory then grab it via iTunes, or email it. Then later you could read it in from somewhere and write it to the persistent store file location (while CoreData is not using it). This approach would be useful for a point-in-time backup of the data for only that one application that is independent from the whole-of-device backup that you get on iCloud/iTunes. It would also enable users to send their entire application data set to other users (if that's of any use), or to recover the application data to a point in time without having to restore the entire device including all other applications.

So I hope that answers your original question. For your follow up queries in the comments...

For multiple devices to share the same data simultaneously, there is CloudKit: https://developer.apple.com/icloud/ . However, I don't know if this works properly with CoreData (I suspect not). (Note that CoreData's own iCloud sync is deprecated in iOS 10.)

(UPDATE: CoreData does work very well with CloudKit now.)

There are also 3rd party alternatives such as Realm: https://realm.io/ . Realm is highly recommended by a lot of developers and is cross platform. But it is an alternative to CoreData, rather than compatible with it (so not quite what you were asking). For data sync between devices, Realm would require you to set up your own data sync server ('Realm Mobile Platform') on either a Mac OS X or a Linux machine which all of your users' devices would need to be able to access via the internet at any time.

Alternatively, you could roll your own solution, but why would you?

Upvotes: 2

Krishna Datt Shukla
Krishna Datt Shukla

Reputation: 997

A very easy way to do this is by using iCloud API and storing all data on iCloud storage. It's very safe and secure for such kind of apps.

Upvotes: 1

Duncan C
Duncan C

Reputation: 131398

That's what iCloud is for. As rmaddy says in his comment, you can back up your core data database to iCloud. I haven't done it, but I've read about it.

Upvotes: 0

Related Questions