10
votes

I've created a JSON string file from an object containing multiple properties. This is the object:

RecipeFile : Codable {
  var name: String
  var theRecipeIngredients: [String]
  var theRecipeSteps: [String]
  var theRecipeRating: Int
  var theRecipeCategory: String
  var theRecipeIndexStrings: String
  var theRecipeImage: String?

I create the JSON string file with this code:

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

I upload it to iCloud Drive. I import the string file from iCloud Drive using UIDocumentPickerViewController. I can parse the imported file just fine. However, I get this message (edited to remove some path info) in the xCode debug area when func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) is called:

[DocumentManager] Failed to associate thumbnails for picked URL file:///....Bourbon%20Chocolate%20Walnut%20Pie18D20181-DAFD-499C-9873-7D3E0794C37A.json with the Inbox copy file:///....Bourbon%20Chocolate%20Walnut%20Pie18D20181-DAFD-499C-9873-7D3E0794C37A.json: Error Domain=QLThumbnail Code=2 "(null)" UserInfo={NSUnderlyingError=0x149a042b0 {Error Domain=GSLibraryErrorDomain Code=3 "Generation not found" UserInfo={NSDescription=Generation not found}}}

Any idea what is causing this to be generated?

The didPickDocumentsAt code starts as follows:

    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
4
Maybe the DocumentManager or an option of it wants to display a thumbnail badly and maybe there‘s an option how it should treat json files? Maybe sth about QLThumbnail? - Fabian

4 Answers

16
votes

You can safely ignore this message. When you import a file from iCloud, iOS tries to copy the thumbnail from iCloud to the imported copy, but for JSON files there's no thumbnail to copy and it logs this. This is not an error on your side.

0
votes

the same thing has happened to me, and I have not found a concrete solution in any forum. But testing, and mixing code that I found in the forums, has finally worked for me. But I don't know exactly what's wrong.

I leave you my code in case it's useful for you, although it's been many months since your question.

func importarCsv(sender: UIBarButtonItem){
let types = [kUTTypePDF,kUTTypeUTF8PlainText]
        let importMenu = UIDocumentPickerViewController(documentTypes: types as [String], in: .import)

        if #available(iOS 11.0, *){
            importMenu.allowsMultipleSelection = false
        }

        importMenu.delegate = self
        present(importMenu, animated: true, completion: nil)

    }



extension MaterialViewController: UIDocumentPickerDelegate{
    internal func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt urls: URL){
        print("urls : \(urls)")
    }

    func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
        print("close")
        controller.dismiss(animated: true, completion: nil)
    }

}
0
votes

I can reproduce this issue with SwiftUI with iOS 14. After Originally I present the UIDocumentPickerViewController after a ToolbarItem pressed and it works fine. Later I refactor the UI and the View is pushed from other parent View and this error occurs and the JSON is not received.

-1
votes

I had this problem when i presented the UIDocumentPicker from another UIViewController before adding it as a child view controller on its parent view controller.