iOS 13图片上传相关适配

1.PHImageManager问题

PHAsset *phAsset = asset;
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
//ptions.deliveryMode = PHImageRequestOptionsDeliveryModeFastFormat;
//是保证 resultHandler 值回调一次,否则可能回回调多次,只有最后一次返回的图片大小等于设置的 targetSize
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.resizeMode = PHImageRequestOptionsResizeModeExact;
options.synchronous = YES;
options.networkAccessAllowed = YES;
CGSize imageSize = [UIImage getImageSizeWithAsset:phAsset];
[[PHImageManager defaultManager] requestImageForAsset:phAsset targetSize:imageSize contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *result, NSDictionary *info) {
    NSMutableData *imageData = [UIImage writeMetaDataWithData:result asset:phAsset];
    [imageData writeToFile:imagePath atomically:YES];
    [[UIImage getSmallImageWithImage:result] writeToFile:smallImagePath atomically:YES];
}];

常规使用情况下deliveryMode 使用PHImageRequestOptionsDeliveryModeFastFormat 在iOS 13时候调用requestImageForAsset会出现result是一张小图(缩略图)

可以通过修改成PHImageRequestOptionsDeliveryModeHighQualityFormat返回设置targetSize对应的图片

这个坑找了很多资料才找到(iOS小菜鸟就这样)

2.CGImageDestinationAddImageFromSource问题

+ (NSMutableData *)writeMetaDataWithData:(NSMutableData *)imageData metaDataDic:(NSDictionary *)metaDataDic {
    NSMutableData *mutableData = [NSMutableData data];
    CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
    CGImageDestinationRef destination = CGImageDestinationCreateWithData(
        (__bridge CFMutableDataRef)mutableData, CGImageSourceGetType(cgImage), 1, nil);
    CGImageDestinationAddImageFromSource(destination, source, 0, (__bridge CFDictionaryRef)metaDataDic);
    CGImageDestinationFinalize(destination);
    CFRelease(source);
    CFRelease(destination);
    return mutableData;
    
//    CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
//    CFStringRef UTI = CGImageSourceGetType(source);
//    CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)imageData, UTI, 1, NULL);
//    CGImageDestinationAddImageFromSource(destination, source, 0, (__bridge CFDictionaryRef)metaDataDic);
//    CGImageDestinationFinalize(destination);
//    return imageData;
}

上面的方法使用注释的代码,在iOS 13上面会导致imageData 被清空为0byte,然后使用新创建一个NSMutableData 却没有这个问题,不知道是啥情况,有知道的iOS大佬可以留言,求告知一下

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、 PhotoKit的变量: PHAdjustmentData: When a user edits an as...
    漓汐Arthur阅读 1,744评论 1 3
  • 父类:NSObject 提供获取或生成预览缩略图和全尺寸图片,或者视频数据的方法。 一、概述 使用这些方法来获取全...
    Shmily落墨阅读 10,574评论 5 6
  • PhotoKit类组成: PHAdjustmentData,继承自NSObject,代表调整的数据.当用户编辑了一...
    小暖风阅读 1,884评论 0 0
  • 因为项目的需求,要捕获相册中的视频与图片,之前也对之尚未做过什么探讨,仅知道iOS8.0后,苹果推出了新的相册管理...
    wizet阅读 28,560评论 22 55
  • 不曾表白的那个女孩,不曾说再见的那个人,不曾看过的书,不曾..…… 那些年来不及完成的梦,那些...
    Liam_629e阅读 201评论 0 0