简体   繁体   中英

iOS 8 (Swift) How do I get rid of this error: ImageIO: PNG zlib error?

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

I encountered the same error on sharing image on iOS8 app. I resolved it by fetching images synchronously like this.

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

Hope this helps.

I got same issue too and try to fix it. Usually the image is storage in iCloud, and you must download it before share.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM