swifton-demand-resources

Use Files after On demand resource download Swift 3


On Demand resource placement.

Hi all. I have set my tags for on demand resources, I have written code to download it but i don't know how to access it? using swift 3

below is my code.

where I get the audio from the main.bundle before i had set up ODR.

 try vox = AVAudioPlayer(contentsOf: URL(fileURLWithPath: Bundle.main.path(forResource: sV, ofType: "mp3")!))
        try music = AVAudioPlayer(contentsOf: URL(fileURLWithPath: Bundle.main.path(forResource: sM, ofType: "mp3")!))

The code for downloading the files.

 request = NSBundleResourceRequest(tags: ["Stress"])
    request.beginAccessingResources { (error) in
        //  Called on background thread
        if error == nil {
            OperationQueue.main.addOperation({ () -> Void in

            })
        }
    }

I just can't see how i would access the file once downloaded?


Solution

  • From the documentation for NSBundleResourceRequest.init(tags:):

    The managed resources are loaded into the main bundle