question

aguella-2168 avatar image
3 Votes"
aguella-2168 asked RobCaplan edited

NSBundle PathsForResources returning null after downloading On Demand Resource Bundle

Hey all,

My team is experiencing a very odd issue with Apple's On Demand Resources framework. We're hitting a randomly occuring issue where a user will successfully download one of our resources yet when we try to access the path of this resource via NSBundle.PathsForResources() it does not show up. When a user gets into this state with a specific resource tag we have not found a way to fix the issue. Our code does attempt to refetch the affected resource tag every time this part of the app is accessed so it's not a matter of not refetching, we are definitely fetching and succeeding in the download. The odd part is that uninstalling the app and reinstalling does not even fix this broken state. One would assume that nothing is carried over between app deletion and reinstall on iOS but that does not seem to be the case here. Additionally this is occurring on seemingly random assets, there is no pattern of certain On Demand Resource Bundles being affected, it's different in all cases. Once the resource tag is "bricked" it remains this way. Any ideas what could be causing this/what we can try to fix this?

Download Code:

             // create and initialize new resource request 
             public async Task CreateODRResourceRequest(string tag) 
             { 
                 if (string.IsNullOrWhiteSpace(tag)) 
                 { 
                     throw new ArgumentNullException(nameof(tag)); 
                 } 
         
                 // Create resource request 
                 var request = new NSBundleResourceRequest(new[] { tag }); 
         
                 // Set highest loading priority 
                 request.LoadingPriority = NSBundleResourceRequest.LoadingPriorityUrgent; 
         
                 _currentResourceRequest = request; 
         
                 var resourcesAlreadyAvailable = await request.ConditionallyBeginAccessingResourcesAsync(); 
         
                 // ensure we only download resource if it's not already on the device 
                 if (!resourcesAlreadyAvailable) 
                 { 
                     await request.BeginAccessingResourcesAsync(); 
                 } 
             } 
dotnet-xamarin
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Do you access the resource after the method BeginAccessingResourcesAsync ?

And try to use the following code

string path = request.Bundle.BundlePath;
 NSFileManager fm = NSFileManager.DefaultManager;
 NSError error;
 string[] contents = fm.GetDirectoryContent(path, out error);
0 Votes 0 ·

Hey Cole! This is our current access code:

         public string GetResourcePath()
         {
             var paths = NSBundle.MainBundle.PathsForResources("zip");
             if (paths.Length == 0)
             {
                 throw new Exception("No zips found in bundle");
             }
             return paths[0];
         }

We don't access by bundle zip name because we are unaware of what the zip name is at that point. Is there any benefit to using NSFileManager?


0 Votes 0 ·

Could you try my code to see what's the value of contents ?

0 Votes 0 ·
Show more comments

0 Answers