iOS 8 (Swift) How do I get rid of this error: Imag

2019-07-05 07:15发布

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

标签: ios swift ios8
2条回答
迷人小祖宗
2楼-- · 2019-07-05 07:22

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.

查看更多
▲ chillily
3楼-- · 2019-07-05 07:40

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

查看更多
登录 后发表回答