14

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
Diskprotek
  • 601
  • 2
  • 7
  • 13
  • 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 Aug 10 '18 at 22:43

4 Answers4

17

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.

Thomas Deniau
  • 2,488
  • 1
  • 15
  • 15
1

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.

Bill Chan
  • 3,199
  • 36
  • 32
0

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

I leave my code here in case it's useful for someone, although it's been many months since this 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)
    }
    
}
Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
-1

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.

Tobe
  • 508
  • 5
  • 14
  • Hmm. I tried your suggestion and it doesn't seem to solve the problem. Instead of presenting the UIDocumentPicker with "present(importMenu, animated: false, completion: nil)", I added it as a child view controller with "self.addChild(importMenu); view.addSubview(importMenu.view); importMenu.didMove(toParent: self)". Same error code pops up. – Diskprotek Nov 06 '18 at 21:23
  • These are completely different things. Sorry but it certainly won't help. – vomi Aug 22 '19 at 11:04