firebase iPhone中未显示聊天

pu82cl6c  于 2022-11-17  发布在  其他
关注(0)|答案(1)|浏览(133)

我使用Angular 14作为前端,Laravel 8作为后端。使用Firebase作为聊天功能。问题是,聊天历史记录显示在笔记本电脑/台式机和Android手机中,但它不显示在iPhone中。x1c 0d1x
几秒的小讲解视频
https://www.loom.com/share/e57b9b47ee924a4aaea26e6c94a03514
第一个

get(ref(this.db, `chats/${this.roomname}`)).then((re) => {
      console.log('chatsssss', re.toJSON());
      re.forEach((e) => {
        const childKey = e.key;
        const data = e.val();
        const chat: any = {};
        chat.nickname = data["nickname"];
        chat.date = formatDate(data["date"], 'yyyy-MM-dd hh:mm:ss', 'en-US');
        chat.type = data['type'];
        chat.message = data['message'];
        this.chats.push(chat);
        console.log("childKey", chat);
        this.scroolToEnd();
      });
x9ybnkn6

x9ybnkn61#

这样做,它就会工作

onChildChanged(ref(this.db, '/chats'), (resp) => {
      this.chats = [];
      if( this.iOS() ){
        //IOS
        resp.forEach((element) => {
          console.log('change', element.val());
          const data = element.val();
          const chat: any = {};
          chat.nickname = data["nickname"];
          // chat.date = formatDate(data["date"], 'yyyy-MM-dd hh:mm:ss', 'en-US');
          chat.date = this.iosDate(data["date"]);
          chat.type = data['type'];
          chat.message = data['message'];
          
          this.chats.push(chat);
          this.scroolToEnd();
        }); 
      }else{
        // not IOS
        resp.forEach((element) => {
          console.log('change', element.val());
          const data = element.val();
          const chat: any = {};
          chat.nickname = data["nickname"];
          chat.date = formatDate(data["date"], 'yyyy-MM-dd hh:mm:ss', 'en-US');
          chat.type = data['type'];
          chat.message = data['message'];
          
          this.chats.push(chat);
          this.scroolToEnd();
        });
      }

      
    });

get(ref(this.db, `chats/${this.roomname}`)).then((re) => {
      console.log('chatsssss', re.toJSON());
      if( this.iOS() ){
        //IOS
        re.forEach((e) => {
          const childKey = e.key;
          const data = e.val();
          const chat: any = {};
          chat.nickname = data["nickname"];
          // chat.date = formatDate(data["date"], 'yyyy-MM-dd hh:mm:ss', 'en-US');
          chat.date = this.iosDate(data["date"]);
          chat.type = data['type'];
          chat.message = data['message'];
          this.chats.push(chat);
          console.log("childKey", chat);
          this.scroolToEnd();
        });
      }else{
        // notIOS
        re.forEach((e) => {
          const childKey = e.key;
          const data = e.val();
          const chat: any = {};
          chat.nickname = data["nickname"];
          chat.date = formatDate(data["date"], 'yyyy-MM-dd hh:mm:ss', 'en-US');
          chat.type = data['type'];
          chat.message = data['message'];
          this.chats.push(chat);
          console.log("childKey", chat);
          this.scroolToEnd();
        });
      }
      
    });
  }

  iosDate(date:any){
    var dateDays = date.split(" ")[0]
    var day = dateDays.split("-")[2]
    var month = dateDays.split("-")[1]
    var year = dateDays.split("-")[0]
    var dateHours = date.split(" ")[1]
    var hour = dateHours.split(":")[0]
    var minutes = dateHours.split(":")[1]
    var seconds = dateHours.split(":")[2]
    var hoursString = ""
    return `${year}-${month}-${day} ${hour}:${minutes}:${seconds}`
}
   iOS() {
    return [
      'iPad Simulator',
      'iPhone Simulator',
      'iPod Simulator',
      'iPad',
      'iPhone',
      'iPod'
    ].includes(navigator.platform)
    // iPad on iOS 13 detection
    || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
  }

相关问题