iosswifton-demand-resources

(ODR) OnDemandResource 'beginAccessingResources was called more than once or at the wrong time (3)


I am trying to introduce ODR in my application and facing the following crash.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'beginAccessingResources was called more than once or at the wrong time (3)'

This is what I have done so far.

  1. Created two asset packs with Tags Bell1 and Bell2.
  2. Requesting for Bell1 tag on appDidFinishLauching after calling conditionallyBeginAccessingResourcesWithCompletionHandler.
  3. Requesting for Bell2 on the viewDidLoad of the Home controller after the login is done.

(Just FYI: I am not calling endAccessingResources anywhere for the time being.)

If I remove the step 3 or request both resources in a single request then the app works fine. If I create two simultenous NSBundleResourceRequest then the app is crashing.

So far I have searched stackoverflow and read the documentation but couldn't find any help regarding this issue.


Solution

  • I have found the problem. I was calling beginAccessingResourcesWithCompletionHandler on a same NSBundleResourceRequest object multiple times.

    So I solved it by creating a new NSBundleResourceRequest instance for each subsequent request.