Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 可能未处理的承诺拒绝(id:0):TypeError:网络请求失败_Firebase_React Native_React Native Android_React Native Ios - Fatal编程技术网

Firebase 可能未处理的承诺拒绝(id:0):TypeError:网络请求失败

Firebase 可能未处理的承诺拒绝(id:0):TypeError:网络请求失败,firebase,react-native,react-native-android,react-native-ios,Firebase,React Native,React Native Android,React Native Ios,我想用react native将包含文本和图像的帖子发送到firebase数据库 问题是我遇到了以下错误: 在PostScreen中,将显示进行post的按钮。在Fire.js中,它被处理并发送到数据库 我希望有人能帮我解决这个错误 PostScreen.js import React,{Component}来自'React'; 进口{ 看法 文本, 样式表, 警觉的, 平面列表, 滚动视图, 安全区域视图, 可触摸不透明度, 形象,, 文本输入, 按钮 许可证Sandroid, 本机模块 }

我想用react native将包含文本和图像的帖子发送到firebase数据库

问题是我遇到了以下错误: 在PostScreen中,将显示进行post的按钮。在Fire.js中,它被处理并发送到数据库

我希望有人能帮我解决这个错误

PostScreen.js

import React,{Component}来自'React';
进口{
看法
文本,
样式表,
警觉的,
平面列表,
滚动视图,
安全区域视图,
可触摸不透明度,
形象,,
文本输入,
按钮
许可证Sandroid,
本机模块
}从“反应本机”;
从“@expo/vector icons”导入{Ionicons};
从“expo常量”导入常量;
从“expo Permissions”导入*作为权限;
从“../src/Fire”导入火;
从“react native image crop picker”导入ImagePicker;
const firebase=require(“firebase”);
要求(“消防基地/消防仓库”);
导出默认类PostScreen扩展组件{
状态={
正文:“,
图像:空,
};
handlePost=()=>{
火,共有的
.addPost({text:this.state.text.trim(),localUri:this.state.image})
。然后(ref=>{
this.setState({text:,image:null});
this.props.navigation.goBack();
})
.catch(错误=>{
警报(错误消息);
});      
};
pickSingle=()=>{
ImagePicker.openPicker({
宽度:500,
身高:500,
裁剪:正确
})。然后(图像=>{
console.log('接收到的图像',图像);
这是我的国家({
image:{uri:image.path,width:image.width,height:image.height,mime:image.mime},
});
}).catch(e=>{
控制台日志(e);
警报。警报(e.message?e.message:e);
});
}
渲染(图像){
返回
}
渲染集(图像){
返回此.renderImage(图像);
}
componentDidMount(){
this.requestCameraRollPermission();
}
getPhotoPermission=async()=>{
const{status}=wait Permissions.getAsync(Permissions.READ\u EXTERNAL\u STORAGE);
如果(状态!=“已授予”){
警报(“我们需要访问您的摄像头”);
}
};
requestCameraRollPermission=async()=>{
试一试{
授予的常数=等待许可和ROID.request(
PERMISSIONS和roid.PERMISSIONS.READ\u外部存储);
如果(已授予===权限sandroid.RESULTS.已授予){
返回null;
}否则{
返回null;
}
}捕捉(错误){
返回null;
}
};
requestCameraPermission=async()=>{
试一试{
授予的常数=等待许可和ROID.request(
权限和roid.PERMISSIONS.CAMERA);
如果(已授予===权限sandroid.RESULTS.已授予){
返回null;
}否则{
返回null;
}
}捕捉(错误){
返回null;
}
};    
render(){
返回(
this.props.navigation.goBack()}>
邮递
this.setState({text})}
值={this.state.text}
>
{this.state.image?this.renderAsset(this.state.image):null}
{this.state.images?this.state.images.map(i=>{this.renderAsset(i)}):null}
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
},
标题:{
flexDirection:'行',
justifyContent:'之间的空间',
水平方向:32,
填充垂直:12,
边界宽度:1,
borderBottomColor:“#D8D9D8”
},
输入容器:{
差额:32,
flexDirection:“行”,
边框宽度:0.5,
边框颜色:“#D8D9D8”
},
化身:{
宽度:48,
身高:48,
边界半径:24,
marginRight:16
},
图标:{
flexDirection:'行',
justifyContent:“柔性端”
},
照片:{
marginRight:20
},
摄像机:{
marginRight:33
},
IMG容器:{
利润率:20
},
按钮:{
背景颜色:“蓝色”,
marginBottom:10,
},
正文:{
颜色:'白色',
尺寸:20,
textAlign:“中心”
},
标题:{
fontWeight:'粗体',
尺寸:22
},
安全区:{
玛金托普:20
},
日期容器:{
flexDirection:'行',
},
IMG视图:{
宽度:“50%”,
玛吉:10,
}

});您必须在函数uploadPhotoAsync中更改此选项 “声明更改”为firebase.storage.TaskEvent.STATE\u已更改

const path = `photos/${this.uid}/${Date.now()}.jpg`;

return new Promise(async (res, rej) => {
  const response = await fetch(uri);
  const file = await response.blob();

  let upload = firebase.storage().ref(path).put(file);

  upload.on(
    firebase.storage.TaskEvent.STATE_CHANGED,
    (snapshot) => {},
    (err) => {
      rej(err);
    },
    async () => {
      const url = await upload.snapshot.ref.getDownloadURL();
      res(url);
    }
  );
});

这对我来说很有用

您必须在函数uploadPhotoAsync中进行更改 “声明更改”为firebase.storage.TaskEvent.STATE\u已更改

const path = `photos/${this.uid}/${Date.now()}.jpg`;

return new Promise(async (res, rej) => {
  const response = await fetch(uri);
  const file = await response.blob();

  let upload = firebase.storage().ref(path).put(file);

  upload.on(
    firebase.storage.TaskEvent.STATE_CHANGED,
    (snapshot) => {},
    (err) => {
      rej(err);
    },
    async () => {
      const url = await upload.snapshot.ref.getDownloadURL();
      res(url);
    }
  );
});

这对我来说很有用

您是否在设备上启用了热重新加载功能?如果是,请尝试禁用它。设备具有活动的internet连接,对吗?@WiliamBrochensquejunior热重新加载已启用,如何禁用它?我正在具有活动internet连接的仿真器上运行该应用程序,因为firebase的身份验证有效。请尝试在终端上运行
adb shell input keyevent 82
,这将动摇仿真器上的设备,并打开一个窗口,您可以在其中禁用它。或者,如果您使用的是AVD,您可以转到“…”按钮,在那里您可以使用传感器晃动设备。将产生相同的效果。对此进行修复的人仍然不起作用@威尔亚姆·布罗肯斯奎尼奥多y