My app uses a-lot of cached images which (I think is the reason causing my app to crash) when i scroll to view so many at one time.
My app is all about images inside list/grid view.
Is it good practice to cache them all?
Note:
Please note I'm using SliverGrid which is loading images lazily.
If you going to manage a buch of amount image is better, download them to a local directory and take the url like a name in a Data Base then you can ask on every request if your url is on your data base if is there then the file in your directory exist if not, you do the request and store it file in directory and name on db. This is better when your app manage a buch of information in cache like image, because on some devices the app can be crash o even restar the device.
Related
I would like to run code to delete files created on local storage when my flutter app is uninstalled. How can I do the same? Is there any event to handle this? If not, how can I clean up the images generated?I don't see any reference online for this.
If you are saving images to users gallery, that image is no longer the domain of your app, in any way shape or form. If you create a gallery within your app this would be different, also, a gallery within your app would in fact be deleted along with any other memory your app uses. I highly doubt you could access users gallery & delete images even with users permission.
Possible backend server solution: here
This indicates this is not possible as per below:
All of your app's files are deleted by the OS when the user deletes
the app. If Apple wanted developers to have that capability, we would
have that capability 🙂
You could make a case for needing to know the app is deleted if you
are storing stuff on the server side. Currently from the server's
point of view there's no way to know whether the app was deleted or
the user just stopped using it. But locally stored files are not an
issue.
I am also looking for a solution to this & I think server logic will get it done.
Must be some sort of logic possible to discover server side if user is GONE!
I am trying to store images locally while the user is running the app and also keep the images stored locally while the app is in the background. When the user terminates the app, then the data should disappear locally and only be loaded once the user reopens the app. I know how to load the images initially, but I am considering where/how to store the images locally.
I know that Swift has the file system, but I was wondering if this is the best practice for this kind of implementation or if there is a better solution.
Doing exactly what you want is not possible, but you can do something similar in functionality.
To cache images you can simply use an existing library, like SDWebImage. It manages asynchronous image downloading and caching for you, and to clear cached images you can simply do
SDImageCache.sharedImageCache().clearMemory()
SDImageCache.sharedImageCache().clearDisk()
Now, as for when you want to clear the cache, it get's a little tricky.
You can't clear the cache when terminating the app, because there is no way to reliably detect when the app is terminated. There is UIApplicationDelegate.applicationWillTerminate method, but it is not called if the app is terminated while in suspended state.
But you can do a workaround: simply clear the cache upon launching the app in UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:), which will be functionally equivalent of what you want to do.
I should hook UIResponder of every app, including SpringBoard and any others. In the hooking, I will write something to the specified file. If I set the path to /var/mobile/Library/MyApp, recommended by Cydia, I found that only the SpringBoard and MyApp could write successfully.
So is there a place every app can write and read?
I admit that I'm not 100% sure on this one, but my guess would be no, there is not a path that every app can writes files to on a jailbroken iPhone.
Certainly, jailbreak apps (installed in /Applications/) on a jailbroken phone can write to locations that can be shared between those jailbreak apps. But, as I understand your question, you would like to inject code into normal, App Store apps, so that those apps can also read and write to the shared location. That part I don't think is possible, because jailbreaking does not completely disable the sandbox for 3rd-party apps installed normally, under /var/mobile/Applications/.
Now, there might be a workaround. There are some shared folders that are accessible to all apps for certain purposes. For example, any app can write images to the saved photos album. What you could try is to take the content of the file you want to write, and encode it as fake image data, in a UIImage (e.g. with [UIImage imageWithData:]). You'd probably need to add a valid image header to the data. Then, you save the file to the photos album, using something like
writeImageToSavedPhotosAlbum:orientation:completionBlock:.
Another app could then find the fake photo by enumerating the saved photos album, and then converting the asset back to image representation to pull the real data back out.
However, this seems quite complicated, and possibly wouldn't work (I haven't tried it). Perhaps you could tell us why you want this shared file. Maybe there's a better way to share the data, without using a globally-accessible file?
Notifications can help you with this. Every app will send interprocess notifications about the events. You could start a daemon that will listen for this notifications and save them in a file. Or you could listen for them in SpringBoard as he can write, for example, to /var/mobile/Media. Depends on what you want to do with this file. Check out my answer here How to create a global environment variable that can be accessed by SpringBoard or other applications in the jailbroken iPhone?
I am storing a lot of images, books, audios etc of my app in
Documents Directory/Library/caches folder.
What happens to all the content if the user updates the version of the app from the app store or from iTunes. Will all of them get erased or will they be untouched during the app updating process?
They will be untouched during the upgrade process. I would like to note however that the Caches folder is meant to be used for data that is just cached rather than data you expect to always be available. The OS reserves the right to get rid of anything in the caches folder. If you're asking this question then I assume you want the data to be persistent so you should be aware that since iOS 5, Apple specifically state that data in the caches directory can be deleted at any time (apart from whilst your app is running).
They are supposed to remain untouched. There are a lot of existing examples for this behavior - try checking any photo sharing application or games that download levels in-game.
What I'm building is simply an application that fetches data over the web and displays them on the iOS views. Data are text and, sometimes, images / music files / movies.
I'd like to use some caching solution for the media. What it needs to do is:
get an url of the file
check if it's alredy downloaded in the cache storage, if it is, serve it
if not, download it
while also checking how much of the storage the current cache uses, and, if it's over the quota, delete oldest files
Best would be to have a simple interface for this - so I can just give an url and get the file of it (while files can change over time and reside on the same URL, so this should be handled too, in a perfect case).
Anyone knows a library to do it, on iPhone/iPad application?
ASIHttpRequest has a DownloadCache option that may work for you. From their documentation:
* You want to have access to the data when there is no internet connection and you can't download it again
* You want to download something only if it has changed since you last downloaded it
* The content you are working with will never change, so you only want to download it once
This is what I used in my iPad app and it works pretty well.
You could try looking at using a UIWebview for the view. If I am understanding this correctly, you will be hosting your content on a web server and would simply like the iOS device to pull the content from the URL. This is what UIWebview is. It is essentially programmable access to Safari.