ios - 在 swift 3,4 中上传相机胶卷中的重复图像

标签 ios swift

我已经使用这个DKImagePickerController一年了,直到最近,我尝试从相机胶卷上传到我的应用程序的多个图像都显示在其中一个图像的重复项中。 IE。我从相册中选择了三张图片,第三张图片上传了三次。我进行了广泛的调试并使用不同的方法来访问图像的数据。我在 swift 3.2 和 4 以及您最新的 beta 版本上使用了 3.8.1 版本。 我将尽可能详细地说明我在单独的测试 session 中使用的内容 swift 3.2 和 4,DK 版本 4.0.0 beta2

let documentDirectory = try! FileManager().url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)

for (i, asset) in assets.enumerated {
    let imageName = "tapan\(i).png"
    self.imgPathUrl = documentDirectory.appendingPathComponent(imageName)
   //loop header is the same for the rest
   asset.fetchOriginalImage(completeBlock: { (image, info) in
      let newImg = self.resizeImage(image!, newWidth: self.view.frame.width) //changes size
      let jpegData = UIImageJPEGRepresentation(newImg, 1)

      do{
        try jpegData?.write(to: self.imgPathUrl, options: .atomic)
      }catch{
         print("Write image to url failed ")
      }

      self.arrSelectedGalleryMedia.add(self.imgPathUrl)
      if self.arrSelectedGalleryMedia.count >= assets.count{
          SharedClass.sharedInstance.hideLoader()
           self.addMedia() //add images
          }
    })
 }

///在单独的循环上

asset.fetchImageData(completeBlock: {(data,info) in
     do{
         try data?.write(to: self.imgPathUrl, options: .atomic)
        }catch{
          print("Error\(error)")
        }

       self.arrSelectedGalleryMedia.add(self.imgPathUrl)
       if self.arrSelectedGalleryMedia.count >= assets.count{
            SharedClass.sharedInstance.hideLoader()
            self.addMedia() //add images
       }
 })

Swift 3.2 和 4,DK 版本 3.8.1

`

asset.fetchOriginalImageWithCompleteBlock({ (image, info) in
  let newImg = self.resizeImage(image!, newWidth: self.view.frame.width)
  let jpegData = UIImageJPEGRepresentation(newImg, 1)

  do{
      try jpegData?.write(to: self.imgPathUrl, options: .atomic)
    }catch{
       print("Write image to url failed ")
    }
   self.arrSelectedGalleryMedia.add(self.imgPathUrl)
   if self.arrSelectedGalleryMedia.count >= assets.count{
        SharedClass.sharedInstance.hideLoader()
        self.addMedia() //add images
    }
})

` 我在 3.8.1 中使用了另一个函数,将数据直接写入临时 URL,并将链接存储在数组中。

问题似乎来自 getImageDataManager().fetchImageData。 就像我提到的示例一样我可以看到 Assets 已被收集,但当我循环每个 Assets 时,它会跳过前两个并在第三个图像上循环三次。 任何帮助将不胜感激...

最佳答案

我使用了不同的库。 TLPhotoPicker 。 DKImagePicker 可能需要首先修复该问题。我之前在 github 开过票。希望他们能为他们的图书馆找到解决方案

extension addMediaViewController: TLPhotosPickerViewControllerDelegate{
    func dismissPhotoPicker(withTLPHAssets: [TLPHAsset]) {
    }
}

关于ios - 在 swift 3,4 中上传相机胶卷中的重复图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49575341/

相关文章:

ios - Alamofire - 如何获取表中的记录数

ios - 在 iOS 中创建按钮面板

ios - 通过 FaSTLane 监控 Git 标签以自动生成构建

ios - "Add photos only"权限选项在 iPhone6S 中不显示,即使在 plist 中添加 "Photo Library Additions Usage Description"之后

ios - 如何暂停或停止当前播放的音频?

ios - 重新加载表时关闭 UISwipeActionsConfiguration

ios - "% is unavailable: Use truncatingRemainder instead"是什么意思?

ios - 将时间戳从 Firebase 转换为 Time Ago

swift - 定义自定义颜色 Swift

ios - NSFileManager fileExistsAtPath 在 segue(并且文件存在)之后为两个不同类中的相同路径返回 true 和 false