CloudKit资产检索成功,但是无法访问数据。错误513

时间:2019-07-17 23:28:25

标签: swift cloudkit

我正在将图像文件存储在CloudKit中,并且可以通过仪表板下载它们,因此我知道插入是正确的。

检索记录时,没有任何错误,并且图像的数据已正确保存在CloudKit缓存文件夹中。我可以从Finder访问缓存文件夹中的资产文件,并且数据正确。

但是,当我尝试创建NSData对象或读取文件时,两者均失败。这个

  for imageRec in ckImages.imageSetsSet
   {

        let asset = imageRec["image"] as? CKAsset
        guard let imageData = NSData(contentsOf: asset!.fileURL) else {
            print("Invalid Image! \(imageRec["imageName"]).")
            sharedLogger.logText(someText: "bad image from download \(imageRec["imageName"]).\n", type : .error)

        }

总是失败。和;

      let fileURL = theStudyFolderURL.appendingPathComponent(imageRec["imageName"]!)
        do
        {
            try FileManager.default.copyItem(at: asset!.fileURL, to: fileURL)
        }
        catch
        {
             sharedLogger.logText(someText: "failed to save file \(imageRec["imageName"]) from cloud.\n", type : .debug)
        }

始终返回错误513(无访问权限)。沙箱功能已关闭。

此功能可检索与“检查”记录相关的图像;

func getImagesForExam(examRecord : CKRecord)
{
    self.imageSetsSet.removeAll(keepingCapacity: true)



    let examRef = CKRecord.Reference(record: examRecord, action: .deleteSelf)

    var predicate = NSPredicate(format: "exam = %@", examRef)

    let query = CKQuery(recordType: "imageRecord", predicate: predicate)

    privateDB.perform(query, inZoneWith: nil)
    { records, error in
        guard let records = records, error == nil else
        {
            self.handle(error: error!)
            return
        }
        for record in records
        {

            self.imageSetsSet.append(record)
        }
        os_log("ckExamModel. loaded images records.", type: .info)
        sharedLogger.logText(someText: "ckExamModel : download image records.\n", type : .debug)

        DispatchQueue.main.async(execute: {() -> Void in

            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "gotImages"), object:nil)

        })

    }

}

正如我所说,图像资产已正确下载到CloudKit缓存文件夹中,但我无法读取该缓存

0 个答案:

没有答案