Storing photos and videos in Core Data?

后端 未结 2 485
悲&欢浪女
悲&欢浪女 2020-12-28 11:22

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

2条回答
  •  再見小時候
    2020-12-28 11:42

    For the photo:

    UIImagePickerController will return us an UIImage inside the memory, so you wouldn't have to do anything, not taking it out of the user's photo library and save it in your core data...

    For the video: You can take the data out using NSData *data = [NSData dataWithContentsOfFile:] or [NSData dataWithContentsOfUrl:] to get the NSData object of the video. You can get the videoUrl easily

    So, I just corrected some of your wrong assumptions first.

    You don't need to save it directly to CoreData. You can save it to your application's document folder and then users will not be able to delete it. Moreover, saving to the application's document folder and only save the link to CoreData will also save your soul from handling big data object.

    The problem may be that you need to deal with your file storage.

    I don't think there is a best practice here.

    Saving in user's photo library will help the users see their photos and videos easier without accessing your app

    Saving in CoreData may be easier for you and may be faster some time

    Saving into file storage may help you not dealing with some binary problem when loading video because Apple MPMoviePlayerController may help you

    For me, because I don't use much SQLite and Core Data, I choose to store into file system

提交回复
热议问题