iOS 8(Swift)如何摆脱这个错误:ImageIO:PNG zlib错误? [英] iOS 8 (Swift) How do I get rid of this error: ImageIO: PNG zlib error?

查看:126
本文介绍了iOS 8(Swift)如何摆脱这个错误:ImageIO:PNG zlib错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用,我想拍摄最近的照片并使用UI活动视图控制器进行分享。出于某种原因,当我尝试分享照片时,我收到错误

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错误

ImageIO: PNG zlib error

以下是相关代码:

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

推荐答案

我在iOS8应用程序上共享图像时遇到了同样的错误。我通过像这样同步获取图像来解决它。

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;

希望这会有所帮助。

这篇关于iOS 8(Swift)如何摆脱这个错误:ImageIO:PNG zlib错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆