iosswift4on-demand-resources

iOS On-Demand Resources - Download Only On Demand. Debuging


I'm using on demand resources for several videos in my app. I have tagged the resources, and put them in the "download only on demand" tag, in the Targets Resource Tags. I download the resources using NSBundleResourceRequest, and it all works great. When I execute the code, the resources get downloaded, and I can see this in the disk section in xcode.

I don't think I need to post my code, for my question.

My question is, when I run the app from xcode on my device, I see that xcode runs the app, and copies the videos to the app right away, even before I execute the download code. Also, if I check my app in the settings, iPhone storage, I see the app is taking up a lot of space since the videos are already downloaded. Why are the videos already taking up storage before they are "downloaded"?

Is this happening only because I am debugging the app, but when I publish the app, the videos will only be downloaded when the user executes the download code?

It seems a basic question, but I cannot see anyone who address this point/

Thanks


Solution

  • Is this happening only because I am debugging the app, but when I publish the app, the videos will only be downloaded when the user executes the download code?

    Yes. The Simulator is not a real device and Xcode is not a server. Your access to the resources is correctly simulated — they are nil until you ask to begin accessing them, and then they start working — so you are able to test, which is all that matters. But to get the real experience you should run thru TestFlight on a device. See https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/On_Demand_Resources_Guide/TestingPerformance.html for more about that.