3

我通过从以下两个答案中获取参考来在我的项目中实现应用程序细化:-

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

下载后如何检测它们的on demand resources位置?

4

3 回答 3

2

最后我发现,如何获取按需资源位置的路径:

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!)}

所以,按需资源的真正位置在这里:

/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

于 2018-01-18T17:37:15.267 回答
2

除非您在初始化资源请求时指定了 bundle,否则资源默认放置在 main bundle 中。因此,例如,如果适合您的资源类型,您可以通过这种方式访问​​它们:

NSString *path= [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4"  ];
于 2017-03-31T17:21:14.413 回答
1

要扩展 saswanb 的答案,您使用的 pathForResource 必须与您添加到 ODR 标记的文件夹或文件名匹配。如果将文件夹的引用添加到 ODR,则可以搜索该文件夹名称,但不能搜索该文件夹的内容。

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

但是,如果您将文件夹的内容添加到 ODR 标记,那么您可以单独搜索每个文件。

于 2017-11-01T21:44:49.960 回答