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

前端 未结 3 342
旧巷少年郎
旧巷少年郎 2021-01-21 05:38

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://stackover
3条回答
  •  时光说笑
    2021-01-21 06:06

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

    func preloadResourcesWithTag(tagArray: Array, 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

提交回复
热议问题