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大佬可以留言,求告知一下

人已赞赏
iOS文章

iOS开发UIView的layoutSubviews子视图布局方法使用

2020-1-10 11:12:59

iOS文章

iOS如何判断设备是否为iPhone X,iOS获取设备型号的方法。

2020-1-10 11:26:41

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索