react-native - 如何使用 react native 计费

标签 react-native in-app-purchase

根据标题,一旦我使用 purchase() 方法,我的应用程序就会崩溃

在一个干净的react-native项目上进行了测试:我实际上只是发出了react-native init testProjnpm installnpm install --save react-native -billingreact-native链接react-native-billing。 然后我继续在我的 MainApplication.java

中设置 new InAppBillingBridgePackage(APP_KEY)

这是我在index.android.js中编辑的唯一代码

export default class testProj extends Component {

  componentDidMount() {
      const InAppBilling = require("react-native-billing")
      console.log(InAppBilling)

      InAppBilling.open()
          .then(() => InAppBilling.purchase('android.test.purchased'))
          .then((details) => {
              console.log("You purchased: ", details)
              return InAppBilling.close()
          })
          .catch((err) => {
              console.log(err);
          });
  }  
  render() {...}

package.json

{
  "name": "testProj",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.0.0-alpha.12",
    "react-native": "0.46.3",
    "react-native-billing": "^2.3.0"
  },
  "devDependencies": {
    "babel-jest": "20.0.3",
    "babel-preset-react-native": "2.1.0",
    "jest": "20.0.4",
    "react-test-renderer": "16.0.0-alpha.12"
  },
  "jest": {
   "preset": "react-native"
  }
}

应用到达此 componentDidMount 后,购买对话框会瞬间加载,然后在后台使我的应用和 Play 商店崩溃。在上述过程中运行 adb logcat *:E 显示:

E/AndroidRuntime(31592): FATAL EXCEPTION: AsyncTask #4
E/AndroidRuntime(31592): Process: com.android.vending, PID: 31592
E/AndroidRuntime(31592): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(31592):    at android.os.AsyncTask$3.done(AsyncTask.java:304)
E/AndroidRuntime(31592):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
E/AndroidRuntime(31592):    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
E/AndroidRuntime(31592):    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
E/AndroidRuntime(31592):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/AndroidRuntime(31592):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/AndroidRuntime(31592):    at java.lang.Thread.run(Thread.java:818)
E/AndroidRuntime(31592): Caused by: java.lang.NullPointerException: Attempt to read from field 'long com.google.wireless.android.finsky.dfe.nano.an.b' on a null object reference
E/AndroidRuntime(31592):    at com.google.android.finsky.billing.lightpurchase.s.a(SourceFile:5)
E/AndroidRuntime(31592):    at com.google.android.finsky.billing.lightpurchase.h.doInBackground(SourceFile:27)
E/AndroidRuntime(31592):    at android.os.AsyncTask$2.call(AsyncTask.java:292)
E/AndroidRuntime(31592):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/AndroidRuntime(31592):    ... 3 more

长话短说:我错过了一些明显的东西吗?

最佳答案

使用静态响应测试应用内结算时会发生这种情况。这看起来像是新版本的 Google Play 商店的问题。我们测试了 3 个版本的 Play 商店。 7.4 可以正常工作,7.8 和 8.0 会崩溃。

目前,我们也在寻找解决方案。

关于react-native - 如何使用 react native 计费,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45166734/

相关文章:

react-native - React Native 渲染头方法

ios - 苹果手机 : why my in-app purchase product array object index set automatically in alphabetical order

react-native - 失败的 Prop 类型无效的 Prop 'value'

javascript - 无法在react-native中加载图像

react-native - 从 React Native 中的视口(viewport)获取 latitudeDelta 和 longitudeDelta

android - Android Google Billing SDK 中未显示介绍价格(印度)

android - 应用内计费 (v3) - 了解空指针异常

objective-c - 恢复应用内购买时不会调用 SKPaymentTransactionStateRestored

ios - 在App Purchase中可以在测试模式下正常运行,但不能在App Review中运行

react-native - React Native React 的多个版本(使用钩子(Hook)时)