fix(lib): Convert PHAsset to JPEG for uploading

This commit is contained in:
maxaggedon 2019-08-14 21:05:04 +02:00 committed by Bartol Karuza
parent dc00a4f115
commit c958493441
1 changed files with 32 additions and 0 deletions

View File

@ -118,6 +118,38 @@ RCT_EXPORT_MODULE()
}
[delegate URLRequest:cancellationBlock didCompleteWithError:error];
}];
} else if (isPHUpload) {
// By default, allow downloading images from iCloud
PHImageRequestOptions *const requestOptions = [PHImageRequestOptions new];
requestOptions.networkAccessAllowed = YES;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
CGSize const targetSize = CGSizeMake((CGFloat)asset.pixelWidth, (CGFloat)asset.pixelHeight);
[[PHImageManager defaultManager] requestImageForAsset:asset
targetSize:targetSize
contentMode:PHImageContentModeDefault
options:requestOptions
resultHandler:^(UIImage * _Nullable image,
NSDictionary * _Nullable info) {
NSError *const error = [info objectForKey:PHImageErrorKey];
if (error) {
[delegate URLRequest:cancellationBlock didCompleteWithError:error];
return;
}
NSData *const imageData = UIImageJPEGRepresentation(image, 1.0);
NSInteger const length = [imageData length];
NSURLResponse *const response = [[NSURLResponse alloc] initWithURL:request.URL
MIMEType:@"image/jpeg"
expectedContentLength:length
textEncodingName:nil];
[delegate URLRequest:cancellationBlock didReceiveResponse:response];
[delegate URLRequest:cancellationBlock didReceiveData:imageData];
[delegate URLRequest:cancellationBlock didCompleteWithError:nil];
}];
} else {
// By default, allow downloading images from iCloud
PHImageRequestOptions *const requestOptions = [PHImageRequestOptions new];