android - Expo in-app-purchases:ReferenceError:找不到变量:connectAsync
问题描述
我正在尝试遵循 expo 的应用程序购买文档。. 我有 android 开发者帐户,并在该帐户上为同一个应用程序设置了我的应用程序内购买。我只是想开始使用文档并立即收到错误。
如果您查看文档,我只是想输入第一个示例中的内容。我在我的应用程序的渲染方法的开头调用了这个函数。
import * as InAppPurchases from 'expo-in-app-purchases';
...
const getHistory = async function(){
const history = await connectAsync();
if (history.responseCode === IAPResponseCode.OK) {
history.results.forEach(result => {
console.log(result)
});
}
}
我收到这些错误
[Unhandled promise rejection: ReferenceError: Can't find variable: connectAsync]
* App.js:57:19 in getHistory
- node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- node_modules/regenerator-runtime/runtime.js:271:30 in invoke
- node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
- node_modules/regenerator-runtime/runtime.js:135:28 in invoke
- node_modules/regenerator-runtime/runtime.js:170:17 in Promise$argument_0
- node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
...
解决方案
由于您使用:
import * as InAppPurchases from 'expo-in-app-purchases';
这意味着您的代码应如下所示: ...
const getHistory = async function(){
const history = await InAppPurchases.connectAsync();
if (history.responseCode === InAppPurchases.IAPResponseCode.OK) {
history.results.forEach(result => {
console.log(result)
});
}
}
推荐阅读
- prestashop - Prestashop 后台“制造商”列中的产品列表过滤问题
- python - 使用 pandas 遍历 excel 行
- unit-testing - 谷歌测试框架无法解析的外部符号
- android - 如何在 android 中为 CardView 制作透明背景?
- pytorch - 使用 conda install 安装 pytorch 和 torchvision 冲突
- git - Visual Studio Code 是否有类似 IntelliJ 的功能“与分支比较”
- python - 使用标准库在 Python 中将 UTC 时间戳转换为 PST
- python - 如何使用训练有素的 keras 模型?
- swift - ios正则表达式提到直到特殊字符+避免空格
- javascript - 调整画布图像大小,如“背景大小:封面”和响应式