如今,我正在研究react-native-iap。
在工作时,我遇到了这个问题。
“未定义您的API”

import RNIap, {
  purchaseErrorListener,
  purchaseUpdatedListener,
  type ProductPurchase,
  type PurchaseError
} from 'react-native-iap';

class RootComponent extends Component<*> {
  purchaseUpdateSubscription = null
  purchaseErrorSubscription = null

  componentDidMount() {
    this.purchaseUpdateSubscription = purchaseUpdatedListener((purchase: ProductPurchase) => {
      console.log('purchaseUpdatedListener', purchase);
      const receipt = purchase.transactionReceipt;
      if (receipt) {
        yourAPI.deliverOrDownloadFancyInAppPurchase(purchase.transactionReceipt)
        .then((deliveryResult) => {
          if (isSuccess(deliveryResult)) {

            if (Platform.OS === 'ios') {
              RNIap.finishTransactionIOS(purchase.transactionId);
            } else if (Platform.OS === 'android') {
              // If consumable (can be purchased again)
              RNIap.consumePurchaseAndroid(purchase.purchaseToken);
              // If not consumable
              RNIap.acknowledgePurchaseAndroid(purchase.purchaseToken);
            }
          } else {
            // Retry / conclude the purchase is fraudulent, etc...
          }
        });
      }
    });

    this.purchaseErrorSubscription = purchaseErrorListener((error: PurchaseError) => {
      console.warn('purchaseErrorListener', error);
    });
  }

  componentWillUnmount() {
    if (this.purchaseUpdateSubscription) {
      this.purchaseUpdateSubscription.remove();
      this.purchaseUpdateSubscription = null;
    }
    if (this.purchaseErrorSubscription) {
      this.purchaseErrorSubscription.remove();
      this.purchaseErrorSubscription = null;
    }
  }
}


在这里,我不确定什么是“ yourAPI.deliverOrDownloadFancyInAppPurchase”?
请帮助,任何人都可以了解“ yourAPI”?

最佳答案

这实际上是您的api :)这意味着在通过本机应用程序内购买购买产品时,您要调用api(后端)。在游戏中的四个示例中,您可以通过应用程序内购买向游戏玩家出售入门包,首先,用户将为此入门包向Google Play或应用商店支付价值。并且您应该知道此操作是否成功完成,并且应该将此入门工具包提供给用户。为此,您应该像backendApi.sold(purchase.transactionReceipt).then((result) => {});一样在此侦听器内进行呼叫

关于javascript - 如何修复“未定义您的API”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57327523/

10-09 15:06