Expo in-app-purchases:ReferenceError:找不到变量:connectAsync

Expo in-app-purchases: ReferenceError: Can#39;t find variable: connectAsync(Expo in-app-purchases:ReferenceError:找不到变量:connectAsync)
本文介绍了Expo in-app-purchases:ReferenceError:找不到变量:connectAsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试关注 expo 的 应用内购买文档..我有 android 开发者帐户,并在该帐户上为同一个应用程序设置了我的应用程序内购买.我只是想开始使用文档并立即收到错误.

I'm trying to follow along with expo's in app purchases documentation.. I have the android developer account and set up my in-app-purchase on that account for the same app. I'm just trying to get started with the documentation and receive an error immediately.

如果您查看文档,我只是想输入第一个示例中的内容.我在我的应用程序的渲染方法的开头调用了这个函数.

If you look at the documentation, I'm just trying to enter in what's in the first example. I call this function at the beginning of the render method of my app.

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';

这意味着您的代码应如下所示:...

That means your code should look like: ...

const getHistory = async function(){ 
  const history = await InAppPurchases.connectAsync();
    if (history.responseCode === InAppPurchases.IAPResponseCode.OK) {
      history.results.forEach(result => {
        console.log(result)
      });
    }
}

这篇关于Expo in-app-purchases:ReferenceError:找不到变量:connectAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)