I am developing an app that lets the user record videos and photos. Now I am wondering what is the best way to store them?
The first idea is of course to save it in the user's photo library, just as if he had recorded the photo from the Camera app, and use a reference to the files. Now there's the problem that the user can access and delete files from the Photos application, which may be still needed by my app. I don't think that I can prevent the user from deleting photos, but how do I deal with the inconsistency my app will suffer from?
The other way would be to take care of the storage myself. My app already uses Core Data, so I could convert the media files using an NSValueTransformer
to an NSData
object and store it as BLOB in Core Data. Then there are some more questions regarding the performance. I know that an SQLite-based Core Data can perfectly handle databases of several GB in size, but loading large data objects will take some time anyway. The obvious advantage is that the user is not going to make my app inconsistent, but is the performance penalty acceptable? And most of all: If I use a UIImagePickerController
to capture photos and videos, it is going to save it in the library anyway. To save it in Core Data, I would have to take the photo from there, convert it to an NSData
object, save it and delete it from the library again. This does not seem to be the right way to me. Also, UIKit provides me a function to get an NSData
object from a photo via UIImageJPEGRepresentation()
, but there seems to be no such function for converting videos.
All in all, because of all those unanswered questions, I would like to use the first approach. But the inconsistency problem puzzles me. What is the best practice to deal with it?