解决办法:
1、修改react-native库
-(id)sendRequest:(NSURLRequest *)request withDelegate: that exists in node_modules/react-native/Libraries/Image/RCTImageLoader.mm
修改成如下内容:
- (id)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate>)delegate
{
@synchronized(self) {
__block RCTImageLoaderCancellationBlock requestToken = ^{};
requestToken = [self loadImageWithURLRequest:request callback:^(NSError *error, UIImage *image) {
@synchronized(self) {
if (error) {
[delegate URLRequest:requestToken didCompleteWithError:error];
return;
}
NSString *mimeType = nil;
NSData *imageData = nil;
if (RCTImageHasAlpha(image.CGImage)) {
mimeType = @"image/png";
imageData = UIImagePNGRepresentation(image);
} else {
mimeType = @"image/jpeg";
imageData = UIImageJPEGRepresentation(image, 1.0);
}
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL
MIMEType:mimeType
expectedContentLength:imageData.length
textEncodingName:nil];
[delegate URLRequest:requestToken didReceiveResponse:response];
[delegate URLRequest:requestToken didReceiveData:imageData];
[delegate URLRequest:requestToken didCompleteWithError:nil];
}
}];
return requestToken;
}
}
2、安装修复工具:patch-package
:
yarn add patch-package postinstall-postinstall
or
npm i patch-package
3、添加脚本:
"scripts": {
...
"postinstall": "patch-package"
4、运行脚本进行修复:
npx patch-package react-native
image.png
5、运行pod install 、react-native run-ios
网友评论