iCloud Drive问题:“ [DocumentManager]无法关联所选URL的缩略图”

Dis*_*tek 4 xcode swift icloud-drive

我已经从包含多个属性的对象创建了一个JSON字符串文件。这是对象:

RecipeFile : Codable {
  var name: String
  var theRecipeIngredients: [String]
  var theRecipeSteps: [String]
  var theRecipeRating: Int
  var theRecipeCategory: String
  var theRecipeIndexStrings: String
  var theRecipeImage: String?
Run Code Online (Sandbox Code Playgroud)

我使用以下代码创建JSON字符串文件:

let json_encoder = JSONEncoder()
let recipeFileName = recipeToDisplay.name! + UUID().uuidString + ".json"
let exportFilePath = getDocumentsDirectory().appendingPathComponent(recipeFileName)
do {
   let jsonData = try json_encoder.encode(exportRecipeFile)
   if let jsonString = String(data: jsonData, encoding: .utf8)
      {
         try jsonString.write(to: exportFilePath, atomically: false, encoding: .utf8)
      }
   } catch {
      print(error.localizedDescription)
   }
Run Code Online (Sandbox Code Playgroud)

我将其上传到iCloud Drive。我使用UIDocumentPickerViewController从iCloud驱动器导入了字符串文件。我可以解析导入的文件。但是,当调用func documentPicker(_控制器:UIDocumentPickerViewController,didPickDocumentsAt urls:[URL])时,我在xCode调试区域中收到了此消息(已编辑以删除一些路径信息):

[DocumentManager]无法将所选URL文件的缩略图:/// .....波旁威士忌%20Chocolate%20Walnut%20Pie18D20181-DAFD-499C-9873-7D3E0794C37A.json与收件箱副本文件:/// .....波旁威士忌相关联%20Chocolate%20Walnut%20Pie18D20181-DAFD-499C-9873-7D3E0794C37A.json:Error Domain = QLThumbnail Code = 2“(null)” UserInfo = {NSUnderlyingError = 0x149a042b0 {Error Domain = GSLibraryErrorDomain Code = 3“未找到生成” UserInfo = {NSDescription =找不到代发}}}

知道是什么导致了这种情况的产生吗?

didPickDocumentsAt代码开始如下:

    let data = try? Data(contentsOf: urls[0]) as Data
    let json_decoder = JSONDecoder()
    do {
        let importRecipeFile = try json_decoder.decode(RecipeFile.self, from: data!)
        let importedRecipeToSave = Recipe(context: theMOC)
        importedRecipeToSave.name = importRecipeFile.name
        importedRecipeToSave.category = importRecipeFile.theRecipeCategory
        importedRecipeToSave.rating = Int16(importRecipeFile.theRecipeRating)
        importedRecipeToSave.terms = importRecipeFile.theRecipeIndexStrings
        importedRecipeToSave.addedToGroceryList = false
Run Code Online (Sandbox Code Playgroud)

Tho*_*iau 5

您可以放心地忽略此消息。当您从iCloud导入文件时,iOS尝试将缩略图从iCloud复制到导入的副本,但是对于JSON文件,没有要复制的缩略图,它会记录下来。这不是您的错误。


Tob*_*obe -1

当我从另一个 UIViewController 呈现 UIDocumentPicker 并将其添加为父视图控制器上的子视图控制器之前,我遇到了这个问题。