5

I have an swift4 app that is having certain issues where on-demand resources packages hang when downloading. The issue appears to be related to different versions of resource bundles being used in testflight environment as opposed to prod. Some users indicate that the packages do not download, but after several days (presumably after the bundles have been purged by the OS), the downloads start working again.

My question is, is there a way to forcibly clear the downloaded bundles rather than waiting for the operating system to remove them at its own leisure. I know it can be done via xcode (via purge in the data panel), but I need a solution that is native to the app itself. (Using the NSBundleResourceRequest.endAccessingResources() function will only stop the resources being used, but will not remove them)

Villainsoft
  • 137
  • 7
  • Per the documentation (https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/On_Demand_Resources_Guide/index.html#//apple_ref/doc/uid/TP40015083-CH2-SW2), once you've "released the tags in local storage" the OS is supposed to purge the resources associated with that asset pack. Can you double check to ensure you're not holding a reference to the tag somewhere (if the docs are correct it seems like they should be deleted immediately when the retain count goes to 0)? – BonanzaDriver Jan 03 '18 at 02:27
  • Also worth noting, the docs say the callbacks to "beginAccessingResourcesXXXX" and "conditionallyBeginAccessingXXXX" need to fire before you invoke "endAccessingResources". – BonanzaDriver Jan 03 '18 at 02:32
  • Did you get an answer to this question? – RJB Apr 11 '19 at 18:24
  • Just as an FYI, assets do not get deleted immediately after the retain count gets to 0, and Apple acknowledges this ( https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/On_Demand_Resources_Guide/index.html#//apple_ref/doc/uid/TP40015083-CH2-SW2 ) in its docs: "An asset pack is eligible for purging when all of the associated tags are no longer retained by any request. The resources associated with a tag may remain on the device for some time before it is purged, including across app launches." I still have not discovered a manual purge mechanism yet. – Brian A May 28 '19 at 21:05

1 Answers1

2

In short, there is no way to delete ODR programmatically. I asked a similar question on Apple Developer forums and got the answer:

There is currently no way to programmatically purge ODR resources. It is up to discretion the OS.

When a new network request for ODR content is initiated, the system will do a sort of inventory check, checking what is currently in memory and if there’s room for new memory. This check also takes into account several other metrics, such as which assets are currently being used, which were used recently, is the asset being used for the UI, etc.

After this is done, the system will determine how much of the chosen assets are to be purged, so that there is enough room to fit the new content. If I remember correctly, the OS will try and delete whole assetpacks. What this means is, if the system is purging assets, it will purge resources that are grouped together such as, all assets from Level 1, Level 2, and Level 3, provided the user is on Level 4. So, the system might purge slighly more space than exactly needed.

If you would like to change your app's ODR assets, you will have to submit an update to your app.

DàChún
  • 4,751
  • 1
  • 36
  • 39