集成react-native-image-picker时,报错Couldn't get file path for photo
1. 版本环境:
"react": "16.13.1",
"react-native": "0.63.2",
"react-native-image-picker": "^2.3.3",
targetSdkVersion: 29。
问题还出现在:Android 10/ API 29..
2.出问题时代码:
<TouchableOpacity
style={styles.addBtn}
onPress={() => this.addImages(options)}>
<Text style={styles.addText}>添加照片</Text>
</TouchableOpacity>
addImages = (options) => {
let { imgUrlArray } = this.state;
let length = imgUrlArray.length;
console.log(length)
if(length === 9) {
return;
}
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri, id: length + 1 + '' };
// You can also display the image using data:
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
imgUrlArray.push(source)
this.setState({
imgUrlArray: imgUrlArray,
});
}
});
}
点击后无反应,但是进入了函数。
解决方法:
方案一: android/app/src/main/AndroidManifest.xml 在application标签中加入
这个办法,能够应用短期修复程序来解决此问题。
我认为这是由于Android 10范围内的存储隐私更改所致,并且将需要更新该库以及它如何从文件系统读取/写入。但是我的Android开发经验非常有限。
import { PermissionsAndroid } from “react-native”
//功能函数中加入...
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'We need your permission'
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('You can use the camera');
ImagePicker.showImagePicker(options, async (response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
console.log(response);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };
}
});
}
else {
console.log('Camera permission denied');
}
集成react-native-image-picker时,报错Couldn't get file path for photo的更多相关文章
- React Native 安卓 程序运行报错: React Native version mismatch(转载)
这个问题已经得到解决,参照stackoverflow上的问题:https://stackoverflow.com/que...这个问题的原因就处在Android工程中app/build.gradle中 ...
- React Native新项目启动报错'React/RCTBridgeDelegate.h' file not found
React Native版本:0.60.4 解决方法: cd ios pod deintegrate pod install 然后重新启动就好了(示例页面变样了( ⊙ o ⊙ )) END------ ...
- npm install模块时 报错:not such file or directory
通过报错信息可以知道,是因为缺少 package.json 这个文件. 解决方法: 首先,初始化项目,一路回车就行 npm init -f 接着安装依赖 npm install formidable ...
- iOS原生项目中集成React Native
1.本文的前提条件是,电脑上已经安装了CocoaPods,React Native相关环境. 2.使用Xcode新建一个工程.EmbedRNMeituan [图1] 3.使用CocoaPods安装Re ...
- react native 之 在现有的iOS工程中集成react native
在现有的iOS工程中集成react native, 或者说将react native引入到iOS 项目,是RN和iOS混合开发的必经之路 参考官网教程:https://reactnative.cn/d ...
- 现有iOS项目集成React Native过程记录
在<Mac系统下React Native环境搭建>配置了RN的开发环境,然后,本文记录在现有iOS项目集成React Native的过程,官方推荐使用Cocoapods,项目一开始也是使用 ...
- linux下, 再次遇到使用thinkphp的模板标签时,报错used undefined function \Think\Template\simplexml_load_string() 是因为没有安装 php-xml包
linux下, 使用thinkphp的模板标签,如 eq, gt, volist defined, present , empty等 标签时, 报错: used undefined function ...
- WPF加载Winform窗体时 报错:子控件不能为顶级窗体
一.wpf项目中引用WindowsFormsIntegration和System.Windows.Forms 二.Form1.Designer.cs 的 partial class Form1 设置为 ...
- iOS原生项目集成React Native模块
今天周末,弄弄Native和React Native之间的交互.首先,先在iOS原生项目中集成React Native模块: 注意事项: 1.因为react native的版本问题,部分细节可能有所不 ...
随机推荐
- 基于asp.net core 从零搭建自己的业务框架(三)
前言 根据业务处理部分,单体马上就能得知错误与否,快速做出处理,而分布式系统,会因为各种原因,无法如同单体一样立刻处理,所以这个时候需要 处理异常 的,做 补偿.转移.人工干预. 当然也可以直接在消费 ...
- 03-注释与API文档
1.注释:Comment分类: 单行注释:// 多行注释:/* */ 文档注释:/** */作用: ① 对所写的程序进行解释说明,增强可读性.方便自己,方便别人 ② 调试所写的代码特点: ①单行注释和 ...
- Navicat15安装教程
本文内容皆为作者原创,如需转载,请注明出处:https://www.cnblogs.com/xuexianqi/p/12797170.html 一:简介 Navicat是一套快速.可靠的数据库管理工具 ...
- Nexus2 上传文件
通过管理界面上传 上传文件 hello-nexus.jar 登录 nexus2 选择第三方库 填写文件信息,完成文件上传 在索引页刷新,可以看到上传的文件 服务器上,文件的存放路径是 sonatype ...
- windows系统下python setup.py install ---出现cl问题,cpp_extension.py:237: UserWarning: Error checking compiler version for cl: 'utf-8' codec can't decode byte 0xd3 in position 0: invalid continuation byte
将cpp_extension.py文件中的 原始的是 compiler_info.decode() try: if sys.platform.startswith('linux'): minimu ...
- MacOS下如何优雅的使用冰蝎
因为冰蝎也是使用 JAVA 写的跨平台应用程序,我们可以借助 macOS 自带的 自动操作 automator.app 来创建一个应用程序. 前言: 冰蝎是一种新型的Webshell连接工具,在日常的 ...
- 恕我直言,你可能真没用过这些 IDEA 插件!
一.前言 IDEA 全称 IntelliJ IDEA,是java编程语言开发的集成环境.IntelliJ在业界被公认为最好的java开发工具. 不是我说的喔,百度百科说的... IDEA 如此好用,插 ...
- C#LeetCode刷题之#28-实现strStr()(Implement strStr())
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3895 访问. 实现 strStr() 函数. 给定一个 hays ...
- Css 设置超过再两行显示省略号
大部分场景都是超过一行就显示... <template> <div class="other-product-item item-name" :title=&qu ...
- kereas 实现鸢尾花分类
import tensorflow as tf from sklearn import datasets import numpy as np x_train=datasets.load_iris() ...