IOS 8 (Swift) How to get rid of this error: ImageIO: PNG zlib error?

I am creating an application and I want to take the latest photo and share it using the UI activity view controller. For some reason, when I try to share a photo, I get an error

ImageIO: PNG zlib error

Here is 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 do not know what happens and where the error arises from

+3
source share
2 answers

I encountered the same error while sharing images in iOS8 app. I resolved it by receiving images synchronously like this.

  PHImageRequestOptions *options = [[PHImageRequestOptions alloc]init]; options.synchronous = YES; 

Hope this helps.

+8
source

I have the same problem too and try to fix it. Typically, an image is a repository in iCloud, and you must upload it before share.

0
source

All Articles