user1203625
user1203625

Reputation: 23

How to restore downloaded media files after iCloud restore?

I have a recipe app which uses core data and in app purchases. Each recipe can have media attachments such as images/videos. Core data only stores recipe text and file paths to those attachments. When i purchase a recipe it is added to db and its media attachments get downloaded to user device. Since those media files are not user created they should not be backed up by iCloud according to iOS Data Storage Guidelines. Now for example I purchased some recipes then I do iCloud restore. After restore I will have those recipes in my database but the media files won't be there anymore. What would be the best way to handle this case?

The only way that comes to my mind is to check at application launch If I have recipes that were purchased in my database, then to check if folder in which media files are stored exists and not empty. If the folder is empty I would then delete purchased entries from db and present an alert to user asking if he would like to re download all his purchases. Then I would use restoreCompletedTransactions facility to download them again.

Upvotes: 0

Views: 274

Answers (1)

Nick Lockwood
Nick Lockwood

Reputation: 40995

You've pretty much answered your own question there - store the filenames in your database, then after restore see if those files are present on the iPhone file system using NSFileManager, and if they aren't, download them again.

Upvotes: 0

Related Questions