Swift 5 Save AVAsset to UserDefaults - swift

Users can scroll through the feed and retrieve videos from my cloud storage.
I would like to cache the videos (which I do successfully temporary in an array) but I want to retrieve the videos also when restarting the App.
Currently, if the user kills the app and starts again the temporary folder is of course empty.
How can I achieve that?

You need to persist the assets. There are several technologies for this, such as files in the user directory, CoreData, SQLite, etc. UserDefaults would not be recommended for such large files.

Related

Download UI contents from a URL in flutter

I am building a flutter app that will contain a lot of animated pictures and 3d objects. Many of those animations will be choosen based on the user choice of gender when registering for the first time. So one of the issues with flutter is that it normally takes a lot of storage and with this animations its gonna need even more storage. So I was wondering if there is a way to keep those animations online in some cloud or in firestore DB and then when the user register for the first time I download it and assign it to the UI to be permenantly there instead of like storing all these Gifs in the assets.
Any suggestiong to avoid storing all of the animations and images in the assets.
Since you said you have lots of images, I would suggest you use a dedicated server to store your images.
If you haven't any dedicated server, then you should use firebase to store your images.
You should follow this link to fetch images from firebase.
Also, you should follow this link to store your images in the cache & in the future fetch from the cache easily.

where to store 100s of images in iPad photo app

i am working on a iPad photo app, where i have to download 100s of images from web and have to store in app locally so that i can access it even if there are no internet connection. So for now i have store it to App's document directory . Is it be ok to store 100s of images in App's Document directory or is there any other way to store it. Please have a reply on it.
Yes you can store it in Document directory.
And also consider its size, if these are big files you can go for zip and save.

Best way to store images in iOS

I was wondering if anyone could suggest the best way for me to store images for my app.
I want to be able to provide an XML update functionality that will allow the user to update their app with a new set of images. I was wondering what the best way to do this was as i need to read and write to the store location. Is storing them in a sqlite database the best way or am i able to use the filesystem to do this without the chance of the iPhone deleting any of the downloaded images?
Thanks
You can write to the filesystem, every app in iOS is sandboxed and has access to his own documents folder.
I would suggest to write on filesystem and only save the urls on the database as that is more performant than saving blobs on a database.
Apple has a good write up about the iOS filesystem.
Alternatively you could implement a solution using SQLite, Apple mentions it in the: Large Data Objects (BLOBs) section here:
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html#//apple_ref/doc/uid/TP40003468-SW5

How can I save images to iphone directory and retrieve it?

I want to save image in iphone album and retrieve them on particular index, how can I?
I have to save profile of many people, along with their images, so how can I access such concept?
Do not save images in iPhone album if they're your application related only.
The better way is to create directory in your application documents directory and store them there. Or even better, do use CoreData and transient property to store image on your disk to keep your data well organized.
you also have choice to save the image in sqlite3 database and retrieve it when needed.

Play specific local IPhone Video

I am in need for some help as I am stuck with a problem with my current IPhone application. I won't go into every details but the mainline is as follow:
I am currently playing videos from a remote URL. Everthing up to this point is working. But we need to add a certain validation as if the video exists on the local IPhone, play this version and otherwise, get the remote version. I get these informations from an XML feed and have the name of the video and it's remote URL.
I've implemented the ALAssetLibrary as a way to retrieve the locals video and transfered 3-4 videos with custom names. After some struggling, I could play these local video. But while I loop through them, all I get is names like 00001.jpg, etc.
Is there any way to get a local video name ? I don't mind if this needs another library but I would appreciate if someone could point me a way of doing it.
Thanks for your time,
AP
You don't have access to the local filenames, and even if you did those filenames would probably not be what you are expecting (i.e. Apple can and probably does rename them while saving them to the Camera Roll).
You can check the metadata on the ALAssetRepresentation for the video to see if a suitable name or other identifier can be found in there. You might also be able to retrieve the raw data and hash it, but that would fail if Apple does any recoding or metadata alteration when saving the video. If your program itself downloads and saves the videos to the Camera Roll using writeVideoAtPathToSavedPhotosAlbum:completionBlock:, you could store the returned assetURL to remember the correspondence. Or you could save the videos to your app's local storage instead of to the Camera Roll, but that would prevent the user from managing the videos with Apple's photo application and such.