window.open() 和 ios 对于异步函数不起作用

window.open() with ios for an async function not working

到目前为止,在我的应用程序中,所有 window.open 调用都可以在 iOS 上正常工作,但这个调用使用的是异步函数。

有解决办法吗? 我花了几个小时尝试来自 Whosebug 的各种东西。

我看到安装 inAppBrowser 可能会有帮助,但我还没有尝试过。 https://capacitorjs.com/docs/apis/browser

我还看到将 window.open 放在点击事件中可能允许它,但这将需要用户进行另一次点击,这是不理想的。

它在 Android 上工作正常。

<ion-button type="button" color="primary" expand="block" (click)="onCreateStripePortalSession()">
        Manage my cards
</ion-button>

async onCreateStripePortalSession() {
    const returnUrl = `https://myapp.app/goto/${this.tenant.slug}/account`;
    try {
      const session = await this.stripeService.createStripePortalSession(this.member.stripeCustomerId, returnUrl);
      if (session.url) {
        // Go to Stripe Customer Portal
        window.open(session.url, '_blank');
      }
    } catch (err) {
      console.log(err);
    }
  }

编辑: 此解决方案不起作用

let wref = window.open();
this.stripeService.createStripePortalSession(...).then(ps => {
  wref.location = ps.url;
});

这不是一个很好的解决方案,因为它要求用户单击两个按钮而不是一个。它通过让用户打开 url 而不是在异步函数中调用它来避免这个问题。

如果有人提出更好的解决方案,我会接受。

    const session = await this.stripeService.createStripePortalSession(this.member.stripeCustomerId, returnUrl);
    if (session.url) {
      // Go to Stripe Customer Portal
      this.notificationService.presentAlertWithExternalUrlOption('Manage my Cards', 'Go to Stripe to manage your cards?', 'Lets go', session.url);
    }
    
     presentAlertWithExternalUrlOption(header: string, message: string, routeLabel: string, url: string) {
        this.alertCtrl.create({
          header,
          cssClass: 'ion-alert-custom',
          message,
          buttons: [
            {
              text: 'Cancel',
              role: 'cancel'
            },
            {
              text: routeLabel,
              handler: () => {
                window.open(url, '_blank');
              }
            },
        ]
        }).then(alertEl => {
          alertEl.present();
        });
      }