【发布时间】:2018-02-22 19:08:23
【问题描述】:
我的 Ionic 3 应用程序运行良好,但应用内购买除外。我正在使用原生的 cordova 通知插件 (link here)。在使用其他 api 时,我并不是最擅长单步执行我的代码,因为我真的需要开始练习。
构建应用时没有出错,点击按钮也没有出错。我简直一窍不通。
this.purchaseId = 'my.sku.that.is.active.in.the.ios.and.android.appstore'
代码:
buyButton() {
this.iap.buy(this.purchaseId)
.then((data) => {
console.log(data)
localStorage.setItem("premium", "1");
this.premiumUser = true;
let toast = this.toastCtrl.create({
message: "You are now a premium user. Congradulations and thank you for contributing.",
showCloseButton: true,
closeButtonText: "Welcome"
});
toast.present();
}).catch((err) => {
let toast = this.toastCtrl.create({
message: err + "",
showCloseButton: true,
closeButtonText: "OK"
});
toast.present();
});
}
没有出现购买框,也没有出现错误。也许有人可能知道修复?您将不胜感激。
catch 语句在 toast 通知中返回“[Object object]”。
【问题讨论】:
-
你是否在浏览器上使用
ionic serve进行测试? -
也许可以尝试在你的 promise.then 中添加一个错误函数,或者在 then 之后添加一个 catch
-
@Sampath 不,我不是在 Ionic Serve 上测试它,而是在运行 ios 10 的 iPad 上测试它。代码在 Android 设备上正常运行,是的,Playstore 和 App Store 上的 SKU 都匹配。嗯……
-
@suraj 我的 catch 语句返回“[object Object]”。我在论坛帖子上更新了我的代码。
-
在你的捕获中做
message: JSON.stringify(err) + "",
标签: cordova typescript ionic-framework in-app-purchase ionic3