React Native 应用内购买(Android)错误

问题描述 投票:0回答:1

该功能在 ios 上运行良好,但在 android 上它在我的物理设备上出现错误。附上屏幕截图。有人遇到同样的问题吗?(https://i.sstatic.net/TMQN8BpJ.jpg)

const handleBuySubscription = async (productId, planType) => {
    setIsRequestInProgress(true);
    try {
      const offer = subscriptionOffers[productId]?.[planType];
      console.log("Selected Product ID:", productId);
      console.log("Selected Plan Type:", planType);
      console.log("Offer:", offer);
      if (Platform.OS === 'android' && offer && offer.basePlanId && offer.offerId) {
        try {
          await requestSubscription({
            sku: productId,
            subscriptionOffers: [{ basePlanId: offer.basePlanId, offerId: offer.offerId }],
          });
        } catch (error) {
          console.error("Error during requestSubscription:", error);
        }
      } else if (Platform.OS === 'ios') {
        await requestSubscription({ sku: productId });
      } else {
        throw new Error("Invalid subscription offer details.");
      }

      setLoading(false);
      setIsRequestInProgress(false);
    } catch (error) {
      setLoading(false);
      setIsRequestInProgress(false);
      if (error instanceof PurchaseError) {
        console.error(`[${error.code}]: ${error.message}`, error);
      } else {
        console.error("handleBuySubscription", error);
      }
    }
  };

尝试了另一种方法 requestPurchase 但没有成功。

android react-native in-app-purchase
1个回答
0
投票

我无法发表评论(但将此视为评论而不是解决方案)

问题似乎是空指针 研究堆栈跟踪,看看您是否可以发现问题,或者将其发布在问题本身中

© www.soinside.com 2019 - 2024. All rights reserved.