I am making an app and I want to take most recent photo and share it using the UI Activity View Controller. For some reason, when I try to share the photo I get the error
ImageIO: PNG zlib error
Here's the relevant code:
let imgManager = PHImageManager.defaultManager()
var fetchOptions = PHFetchOptions()
let screenSize: CGSize = UIScreen.mainScreen().bounds.size
let targetSize = CGSizeMake(screenSize.width, screenSize.height)
var imagesArray: NSMutableArray = []
fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: true)]
if let fetchResult = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image, options: fetchOptions) {
imgManager.requestImageForAsset(fetchResult.lastObject as PHAsset, targetSize: targetSize, contentMode: PHImageContentMode.AspectFill, options: nil, resultHandler: { (image, _) in
imagesArray.addObject(image)
})
}
let activityViewController = UIActivityViewController(
activityItems: imagesArray,//[textField.text as NSString],
applicationActivities: nil)
presentViewController(activityViewController, animated: true, completion: nil)
I don't know what's going on and where the error is coming from