简体   繁体   English

按需资源是否允许存档文件?

[英]Is archive files allowed on On-Demand Resource?

We have.zip file in app, tagged as on demand resource.我们在应用程序中有.zip 文件,标记为按需资源。 On downloading it we get success in NSBundleResourceRequest completion handler, but unable to find path of downloaded file(.zip).在下载它时,我们在 NSBundleResourceRequest 完成处理程序中获得成功,但无法找到下载文件(.zip)的路径。 It works fine for png and jpg file but fails for.zip files.它适用于 png 和 jpg 文件,但适用于 .zip 文件。 Also.zip file download works fine in our testing devices and fails only on App Reviewer devices.此外,zip 文件下载在我们的测试设备中运行良好,仅在 App Reviewer 设备上失败。

Any alternative for.zip in iOS will work on ODR? iOS 中的.zip 的任何替代方案都适用于 ODR?

Are you using conditionalyBeginAccessingResources method before beginAccessingResources ?您是否在beginAccessingResources之前使用conditionalyBeginAccessingResources方法?

Resources:资源:

Check this nice ODR ios tutorial from Ray, and this book from Vandad (it contains a section for propper ODR fetching).查看 Ray 的这个漂亮的ODR ios 教程和 Vandad 的这本书(它包含一个关于适当的 ODR 获取的部分)。

From the Ray's tutorial:来自 Ray 的教程:

class ODRManager {

  // MARK: - Properties
  static let shared = ODRManager()
  var currentRequest: NSBundleResourceRequest?

  // MARK: - Methods
  func requestFileWith(tag: String,
                        onSuccess: @escaping () -> Void,
                        onFailure: @escaping (NSError) -> Void) {

    currentRequest = NSBundleResourceRequest(tags: [tag])

    guard let request = currentRequest else { return }

    request.endAccessingResources()

    request.loadingPriority =
    NSBundleResourceRequestLoadingPriorityUrgent

    request.beginAccessingResources { (error: Error?) in
      if let error = error {
        onFailure(error as NSError)
        return
      }

      onSuccess()
    }
  }
}
In use: 正在使用:
let tag = "<#tagString#>"
var currentResourcePack: NSBundleResourceRequest? = NSBundleResourceRequest(tags: [tag])
guard let req = currentResourcePack else { return }

req.conditionallyBeginAccessingResources { available in
  if available {
    self.displayImagesForResourceTag(tag)
  } else {
    // this usualy means that the resources are not downloaded so you need to download them first
    req.beginAccessingResources { error in
      guard error == nil else {
        <#/* TODO: you can handle the error here*/#>
        return
      }
      self.displayImagesForResourceTag(tag) 
    }
  }
}

func displayImagesForResourceTag(_ tag: String) {
  OperationQueue.main.addOperation {
    for n in 0..<self.imageViews.count {
      self.imageViews[n].image = UIImage(named: tag + "-\(n+1)")
    }
  }
}

From the book:从书中:

 let tag = "<#tagString#>" var currentResourcePack: NSBundleResourceRequest? = NSBundleResourceRequest(tags: [tag]) guard let req = currentResourcePack else { return } req.conditionallyBeginAccessingResources { available in if available { self.displayImagesForResourceTag(tag) } else { // this usualy means that the resources are not downloaded so you need to download them first req.beginAccessingResources { error in guard error == nil else { <#/* TODO: you can handle the error here*/#> return } self.displayImagesForResourceTag(tag) } } } func displayImagesForResourceTag(_ tag: String) { OperationQueue.main.addOperation { for n in 0..<self.imageViews.count { self.imageViews[n].image = UIImage(named: tag + "-\(n+1)") } } }

So, maybe you can dig out the source of zip there?那么,也许你可以在那里挖掘出 zip 的来源?

Alternative way替代方式

Another solution is to download the zip, extract it and start using resources from the extract sandbox destination folder by using the FileManager, and use Bundle only when ODR are not or can't be downloaded.另一种解决方案是下载zip,通过FileManager解压并开始使用解压沙箱目标文件夹中的资源,仅在没有或无法下载ODR时使用Bundle。

GL总帐

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM