TGCameraViewController icon indicating copy to clipboard operation
TGCameraViewController copied to clipboard

Refactored saveJPGImageAtDocumentDirectory:image:resultBlock:failureBlock

Open lichenglu opened this issue 8 years ago • 3 comments

Hi, I posted an issue yesterday, and then decided to take a look at why I have the problem. I found some issues(sorry if I misunderstood your code purpose) and "fixed" the following:

  1. Refactored the way to get directory by using NSFileManager, which is recommended by Apple
  2. Only tried to create the image directory when the directory does NOT exist.
  3. Use NSFileManager to save the image to documents/Images, and trigger failure block if writing is not successful.
  4. Init assetURL with NSURL(fileURLWithPath:) so that the returned url can be used directly for loading the image

lichenglu avatar Oct 22 '16 20:10 lichenglu

Hmm...why I cannot pass the travis build?

lichenglu avatar Oct 22 '16 20:10 lichenglu

Hey @lichenglu! Your changes look good! Thanks for contributing. I replied to your issue #79, because I only did not understand how to reproduce the issue, or if it happens all the time.

Please reply there so I can reproduce it and test your code before I merge it! :)

PS: Don't mind the Travis build, it always fails for no reason. I'll test it locally.

macecchi avatar Oct 22 '16 21:10 macecchi

Hi @lichenglu! I'm so sorry I took so long to review your PR. I was testing it now but I have some questions.

When cameraDidSavePhoto is called and the option kTGCameraOptionSaveImageToAlbum is set to true, I'm not able to load the contents of the url returned (assets-library://asset/asset.JPG?id=DEC2E2DA-25AF-43AA-B0FB-40CB9B475C7D&ext=JPG)

    func cameraDidSavePhoto(atPath assetURL: URL!) {
        print("cameraDidSavePhotoAtPath: \(assetURL)")
        guard let data = try? Data(contentsOf: assetURL) else { return } // Always returns
        let image = UIImage(data: data)
        print(image)
    }

macecchi avatar Jan 05 '17 21:01 macecchi