【问题标题】:My profile pic only appears after I touch it on app load我的个人资料图片仅在我在应用加载时触摸它后才会出现
【发布时间】:2020-07-04 08:19:59
【问题描述】:

我使用 Ionic 4、Firebase、Angular 创建了一个社交媒体应用,它在 Android 上运行良好。但是在 iOS 上,当我加载应用程序时,我的个人资料图片不会出现,除非我实际触摸它。

这是代码

  async ngOnInit() {
    firebase.auth().onAuthStateChanged(user => {
      console.log('onAuthStateChanged', user.uid);

      this.currentUser = user;
      this.imageService.getImageDownloadUrl( 'profilePicture', user.uid)
      .then((photo) => {
        console.log('getImageDownloadUrl', photo);

        this.profilePicture = (photo === 'undefined') ? 'false' : photo;
        console.log('profilePicture', this.profilePicture);
      });
    });
  }
  <div class="profilePhoto" [ngSwitch]="profilePicture">
    <div *ngSwitchDefault>
    <img [src]="profilePicture" (click)="Present('profilePicture')">
  </div>
  <div class="logo" *ngSwitchCase="'false'">
    <ion-img style="padding-top: 25px; " src="assets/image/SpaghettiPlus2.png" (click)="openImagePicker('profilePicture')"></ion-img>
  </div>
</div>

我不必在 Android 上触摸图片,它只是在加载时出现,但在 iOS 上,它不会加载实际图片,它只会保留默认图片,直到我真正触摸图片然后神奇地出现。

【问题讨论】:

  • 在您在 iOS 上点击之前,该应用是显示您的默认图片还是两张图片都不显示?你如何测试这些平台 - 模拟器,通过 xcode 构建,...?
  • 当我上传个人资料图片时,它会在应用程序和 Firebase 中正确加载。一旦我关闭应用程序并重新打开它,它就会恢复为我的默认图片。这只发生在IOS中。 Android 会加载存储在 Firebase 中的个人资料图片。
  • 所以您将图片保存在 Firebase 存储中,不是吗?您是否为 iOS 设置了 Firebase 存储?或许this可以帮到你
  • 是的,我有。并且在 Android 上一切正常。
  • 嗯。我真的不知道如何解决这个问题。通常会出现这些 iOS 问题,因为环境更严格遵循某些标准(例如,角度日期管道不适用于 Firefox 中的所有日期格式),但在您的示例中很难说。我是否还有其他想法我会再次发表评论,否则祝你好运。

标签: angular typescript firebase ionic4


【解决方案1】:

尝试使用 NgZone,因为我使用下面的代码可能会得到你想要的东西

 constructor(ngZone: NgZone){ }

async ngOnInit() {
  firebase.auth().onAuthStateChanged(user => {
    this.currentUser = user;
    this.imageService.getImageDownloadUrl('profilePicture', user.uid)
      .then((photo) => {
        console.log('getImageDownloadUrl', photo);

        this.ngZone.run(() => {
          this.profilePicture = (photo === 'undefined') ? 'false' : photo;
          console.log('profilePicture', this.profilePicture);
        }
          });
  });
}

【讨论】:

    猜你喜欢
    • 2012-02-25
    • 2021-12-30
    • 2012-02-19
    • 2011-07-08
    • 2018-06-16
    • 1970-01-01
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多