PHAsset - Property way to save captured PHAssets locally? (in app)

1k views Asked by At

trying to understand the concept for Photos/Photos.h framework.

my goal is:

  1. write captured video url (or asset) to app's "userDefaults".
  2. read from "userDefaults", & fetch each saved asset data (thumbnail & url)
1

There are 1 answers

1
Mozahler On

Since you're not providing any code (nor asking for any), I can help sort some of this out for you -- but you need to study a bit more before you can put it all together. Especially if you think you've asked a question which has one simple correct answer.

UserDefaults is not a good place to store an image. Images are big. (You should look at Apple's documentation of what UserDefaults is for/how it's intended use).

UserDefaults

There's more than one place to store images. Do you want the system to delete them if you start running out of memory? Then it belongs in cache:

let cachesPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).last!

Do you want to depend on it being around the next time the app is run? There is a standard place for that as well:

let userDocumentsFolder = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]

Do you want iTunes to back up the images for you automatically? It expects files to be in a certain place for automatic backup. Do you have a way to keep track of where it is (the path to the file can change if the app is re-run). For that you might require persistent storage, so CoreData or Realm might be an option for you. Or you could scan your directory and create a list of files you've already saved. Then you'll need a way to select the correct one. (What did you call it? Should the user select it?)

Apple has very clearly written and useful documentation on access to the Photos library and using PHAssets. Here's just one example:

PHAsset - Photos

There are a lot of talented people on this site, and they are willing to help you, but you need to do your homework before coming here.

I recommend you read these linked documents, start writing some code, and if you run into problems please come back and ask any specific question you have about any specific problem you've encountered. Include the code which causes the problem, as well as the exact error message you are getting. We will be glad to help.