3

I implement the app thinning in my project by getting the reference from below two answers:-

  1. https://stackoverflow.com/a/33145955/988169
  2. https://stackoverflow.com/a/31688592/988169

How to detect where the on demand resources are located after being downloaded?

Community
  • 1
  • 1
pkc456
  • 8,350
  • 38
  • 53
  • 109
  • Check the comments in the link http://stackoverflow.com/questions/33824528/on-demand-resources-in-ios-9-how-to-find-out-exact-location-of-downloaded-reso – Muneeba Nov 20 '15 at 12:21
  • I am getting the type. Can you post a detailed answer. – pkc456 Nov 23 '15 at 05:50

3 Answers3

2

Unless you specified a bundle when you initialized the resource request, the resources are placed in the main bundle by default. So for example, you could access them this way, if appropriate to your type of resource:

NSString *path= [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4"  ];
saswanb
  • 1,975
  • 1
  • 17
  • 25
  • this doesn't work for me. I have a file in resources folder of my project (not in assets). Without on demand tag, I can get it with pathForResource method. Once I'm adding on demand tag to it - this method doesn't work(( – Anton Eregin Jan 17 '18 at 20:08
  • You might try using a group rather than a folder. That's how I ended up doing it, and the above works with that configuration. – saswanb Jan 18 '18 at 16:50
  • He specifically said it's an *on demand* resource -- which by definition requires a tag, placing it in a different bundle than main. – Hashman Nov 17 '18 at 23:15
  • @Hashman That's exactly what I'm talking about, a tagged ODR resource, and last time I wrestled with ODR, if you don't tell it a different bundle name, it goes in the main bundle – saswanb Nov 19 '18 at 16:57
  • @Anton Eregin Did you get this working? I am also facing the same issue. – Yogi Aug 21 '20 at 02:24
  • 1
    @Yogi no, I just looked for AWS S3 and integrated AWS SDK for iOS, for the last 2,5 years it works like a charm – Anton Eregin Aug 22 '20 at 18:49
2

Finally I've found, how to get a path of on demand resources location:

func preloadResourcesWithTag(tagArray: Array<Any>, resourceName: String ){

    let tags = NSSet(array: tagArray)
    let resourceRequest:NSBundleResourceRequest = NSBundleResourceRequest(tags: tags as! Set)
    resourceRequest.beginAccessingResources { (error) in
        OperationQueue.main.addOperation{
            guard error == nil else {
                print(error!);
                return
            }

                print("Preloading On-Demand Resources ")

            let _path1 = resourceRequest.bundle.path(forResource: "img2", ofType: "jpg")
            let img = UIImage(contentsOfFile: _path1!)}

So, the real location of on demand resources is here:

/Users/admin/Library/Developer/CoreSimulator/Devices/250101ED-DFC5-424C-8EE1-FC5AD69C3067/data/Library/OnDemandResources/AssetPacks/com.ae.OfflineMapSwiftV1/1629348341761109610/com.##.OfflineMapSwiftV1.asset-pack-000000G31NNOJ.assetpack/img2.jpg

Anton Eregin
  • 8,140
  • 1
  • 12
  • 14
1

To expand upon saswanb's answer, the pathForResource you use has to match the folder or filename you added to the ODR tag. If you add a reference to a folder to an ODR, you can search for that folder name, but not the contents of the folder.

NSString *path= [[NSBundle mainBundle] pathForResource:@"ODRFolder1" ofType:nil  ];

But if you add the contents of the folder to the ODR tag, then you can search for each file individually.

B. Desai
  • 16,414
  • 5
  • 26
  • 47
Sumasshu
  • 11
  • 2
  • 1
    if you want to expand on someones answer you should edit their answer, not create your own – 0TTT0 Nov 01 '17 at 22:15