我通过从以下两个答案中获取参考来在我的项目中实现应用程序细化:-
下载后如何检测它们的on demand resources
位置?
我通过从以下两个答案中获取参考来在我的项目中实现应用程序细化:-
下载后如何检测它们的on demand resources
位置?
最后我发现,如何获取按需资源位置的路径:
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
除非您在初始化资源请求时指定了 bundle,否则资源默认放置在 main bundle 中。因此,例如,如果适合您的资源类型,您可以通过这种方式访问它们:
NSString *path= [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4" ];
要扩展 saswanb 的答案,您使用的 pathForResource 必须与您添加到 ODR 标记的文件夹或文件名匹配。如果将文件夹的引用添加到 ODR,则可以搜索该文件夹名称,但不能搜索该文件夹的内容。
NSString *path= [[NSBundle mainBundle] pathForResource:@"ODRFolder1" ofType:nil ];
但是,如果您将文件夹的内容添加到 ODR 标记,那么您可以单独搜索每个文件。