- Home /
Caching Unity Web Request downloaded Asset Bundles denied by iOS
I have set up asset bundles downloads via Unity Web Request for a mobile app that I'm working on in Unity. The downloading and caching seems to work just fine in the Unity Editor but when I build the app and run it on iOS, I get this error:
UnauthorizedAccessException: Access to the path "Saturday, September 14, 2019" is denied.
This is in reference to the path that I'm generating based on the date of the download. Here is my code:
public IEnumerator DownloadAndCacheMyaamiakiAssetBundle(string uri)
{
//Create new cache
string today = DateTime.Today.ToLongDateString();
Directory.CreateDirectory(today);
Cache newCache = Caching.AddCache(today);
//Set current cache for writing to the new cache if the cache is valid
if (newCache.valid)
Caching.currentCacheForWriting = newCache;
//Download the bundle
UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(uri);
request.SendWebRequest();
while(!request.isDone)
{
progress.fillAmount = request.downloadProgress;
}
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);
//Get all the cached versions
List<Hash128> listOfCachedVersions = new List<Hash128>();
Caching.GetCachedVersions(bundle.name, listOfCachedVersions);
//This is if we only want to keep 1 local caches at any time
if (Caching.cacheCount > 1)
Caching.RemoveCache(Caching.GetCacheAt(1)); //Removes the oldest user created cache
Since this code is just a modified version of the example given by Unity for Caching (https://docs.unity3d.com/ScriptReference/Caching.html) , I'm having trouble figuring out why iOS is denying me access to this cache file.
Any suggestions? Thanks, Kurt
Your answer
Follow this Question
Related Questions
Addressable Assets Cache 0 Answers
How Unity Generates Cache Hash For AssetBundles 1 Answer
How to keep Adressable Asset Bundles downloaded in device? 1 Answer
AssetBundles caching bug? 1 Answer