gpt4 book ai didi

javascript - Imagepicker React Native 在 iOS 上崩溃但在 Android 上运行良好

转载 作者:行者123 更新时间:2023-12-05 05:04:35 24 4
gpt4 key购买 nike

我目前在 React Native 上使用图像选择器。当我使用 android 来选择图像时,它工作正常。但是,当我使用 iOS 时,它会在我选择照片时崩溃。

这是它在 xcode 调试器中显示的错误:

2020-04-03 11:54:27.802434+0800 app[7218:1993193] -[NSURLResponse allHeaderFields]: unrecognized selector sent to instance 0x28281aba0 2020-04-03 11:54:27.802766+0800 app[7218:1993193] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLResponse allHeaderFields]: unrecognized selector sent to instance 0x28281aba0' * First throw call stack: (0x19d01c164 0x19cd30c1c 0x19cf1a7e0 0x19d02085c 0x19d022b60 0x102b27bc8 0x102b27a90 0x102b01ce0 0x1059f5d10 0x1059f718c 0x1059fe968 0x1059ff580 0x105a0b0f0 0x19cd23714 0x19cd299c8) libc++abi.dylib: terminating with uncaught exception of type NSException

这是我的代码:

chooseImage = async (id) => {
//await this.askPermissionsAsync();
let options = {
title: 'Select Image',
storageOptions: {
skipBackup: true,
path: 'images',
},
};
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response.error);

if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else {
const source = { uri: response.uri };

// You can also display the image using data:
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
// alert(JSON.stringify(response));


let file_data = [...this.state.fileData];
file_data[id] = response.data;

let file_uri = [...this.state.fileUri];
file_uri[id] = response.uri;

this.setState({filePath:response, fileData: file_data, fileUri: file_uri});
}
});
}

我还在info.plist中添加了权限:

    <key>NSCameraUsageDescription</key>
<string></string>
<key>NSPhotoLibraryUsageDescription</key>
<string></string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string></string>
<key>NSDocumentsFolderUsageDescription</key>
<string></string>

但问题仍然存在于 ios 中。

最佳答案

问题是

'data:image/jpeg;base64,' + this.state.fileData[id]

同时在 Image 标签上渲染它。此处指出了此问题:

YellowBox Crash

Image Crash with data:image/png;base64

我做的解决方案是在选项上添加“noData: true”并直接访问图像标记中的 URI 文件位置。

希望对你有帮助

关于javascript - Imagepicker React Native 在 iOS 上崩溃但在 Android 上运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61004986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com