0

When creating a NSAttributedString from an HTML string which contains an image link (https), somehow the downloaded image is cached. How did I came up with this fact?

  1. Install app.
  2. Open the app. Image is there.
  3. Close the app (terminate). Go for Airplane mode.
  4. Open the app. Image is still there.
  5. Delete the app completely, and reinstall.
  6. Open app while still in airplane mode. No image.

Caching the image is actually what I want. But I want to know deeper, how and where the image is cached. Since my app should work offline, I have to be sure that the image is cached or not. I dig into the docs and couldn't find anything. Can someone enlighten me? Thank you.

EDIT to clarify:

I am not using NSTextAttachment directly. I'm initializing NSAttributedString from a String, using UTF8 encoded data. Why I am talking about NSTextAttachment is I guess its automatically creating an NSTextAttachment for "img" tags in the HTML String.

Arda Oğul Üçpınar
  • 881
  • 1
  • 14
  • 38

2 Answers2

0

As the docs don't state that the images will be cached, it's best to assume that there is no caching. Therefore, the best solution to your situation is to download the file with URLSession and store the file on disk, so when the device is offline, the image can be displayed.

Papershine
  • 4,995
  • 2
  • 24
  • 48
0

Some digging into the simulator data proved that my image is really cached.

/Users/<username>/Library/Developer/CoreSimulator/Devices/<simulator-id>/data/Containers/Data/Application/<app-id>/Library/Caches/<app-bunle-identifier>/Cache.db file is a SQLite file holding the cache info. And there is my image, with its link and its data.

Its odd that Apple didn't documented this, and I still don't know how / when it caches.

Arda Oğul Üçpınar
  • 881
  • 1
  • 14
  • 38