【发布时间】:2021-04-06 17:22:32
【问题描述】:
我正在使用应用内购买,如果由于某种原因我无法从 Google 或 iOS 应用商店检索产品信息,我想将 UI 更改为“不可用”。
ionViewDidEnter() {
this.platform.ready().then(async () => {
firebase.auth().onAuthStateChanged(async user => {
this.currentUser = user;
});
this.unavailable = await this.setupProducts();
console.log('available', this.unavailable);
});
}
setupProducts(): Promise<boolean> {
let productWWHS: string;
let productISA: string;
if (this.platform.is('ios')) {
productWWHS = 'prodID';
productISA = 'prodID';
} else if (this.platform.is('android')) {
productWWHS = 'prodID';
productISA = 'prodID';
}
this.inAppPurchase.ready(() => {
this.products.push(this.inAppPurchase.get(productWWHS));
this.products.push(this.inAppPurchase.get(productISA));
if (!this.products[0]) {
return true;
}
});
return false;
}
我在这个方法中做错了,它有错误 类型 'boolean' 不能分配给类型 'Promise'
我想以某种方式断言 inAppPurchase.get() 已经返回了一些东西,但它没有返回一个承诺。
有没有更好的方法来做到这一点?
任何帮助将不胜感激。
【问题讨论】:
标签: javascript typescript async-await promise in-app-purchase