TGCameraViewController
TGCameraViewController copied to clipboard
Refactored saveJPGImageAtDocumentDirectory:image:resultBlock:failureBlock
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:
- Refactored the way to get directory by using NSFileManager, which is recommended by Apple
- Only tried to create the image directory when the directory does NOT exist.
- Use NSFileManager to save the image to documents/Images, and trigger failure block if writing is not successful.
- Init assetURL with NSURL(fileURLWithPath:) so that the returned url can be used directly for loading the image
Hmm...why I cannot pass the travis build?
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.
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)
}