到目前為止,在我的應用程式中,所有 window.open 呼叫在 iOS 上都可以正常作業,但這個呼叫使用的是異步函式。
有解決方案嗎?我花了幾個小時從 stackoverflow 嘗試各種東西。
我已經看到安裝 inAppBrowser 可能會有所幫助,但我還沒有嘗試過。 https://capacitorjs.com/docs/apis/browser
我還看到將 window.open 放在 click 事件中可能會允許它,但這將需要用戶進行另一次不理想的點擊。
它在 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;
});
uj5u.com熱心網友回復:
這不是一個很好的解決方案,因為它需要用戶單擊兩個按鈕而不是一個按鈕。它通過讓用戶打開 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();
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/379564.html
上一篇:為什么orderByChild不在AngularFireforRealtime資料庫中排序?
下一篇:運行離子服務時出錯:[ng]錯誤:AngularCompiler需要TypeScript>=4.4.2和<4.5.0但找到了4.5.2
