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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 21:31:58

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/28117605/ios-8-swift-how-do-i-get-rid-of-this-error-imageio-png-zlib-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!