首页 > 解决方案 > purchaserInfoUpdateListener 从不调用 RevenueCat

问题描述

我正在使用 RevenueCat 的 React Native SDK。

我正在遵循官方示例。

我可以在 iOS 上进行购买并得到You're all set. Your purchase was successful提示。

问题是purchaserInfoUpdateListener永远不会被调用,并且购买总是被catch阻止,我无法验证我的代码中是否已成功购买。

可能是什么问题呢?

async componentDidMount() {
    try {
     
      this.purchaserInfoUpdateListener = (info) => {
          console.log('purchaserInfoUpdateListener:: ', info )
          checkIfPro(info);
      };
     
      this.shouldPurchasePromoProduct = async deferredPurchase => {
        this.deferredPurchase = deferredPurchase;
      };
     
      Purchases.addPurchaserInfoUpdateListener(this.purchaserInfoUpdateListener);
      Purchases.addShouldPurchasePromoProductListener(this.shouldPurchasePromoProduct);

    } catch (e) {
      console.log("Error handling");
    }
}

async componentWillUnmount() {
    Purchases.removePurchaserInfoUpdateListener(this.purchaserInfoUpdateListener);
    Purchases.removeShouldPurchasePromoProductListener(this.shouldPurchasePromoProduct);
}

 onPress={async () => {
    const aPackage = this.state.offerings.current.availablePackages[0];
    
    try {
      const purchaseMade = await Purchases.purchasePackage(aPackage);
      checkIfPro(purchaseMade); //never called
      console.log('purchaseMade:: ',purchaseMade) //never called
    } catch (e) {
      if (!e.userCancelled) {                        
        console.log(`Error handling ${JSON.stringify(e)}`);
      } else {  
        console.log(`User cancelled ${JSON.stringify(e)}`);
      }
    }
 }}

日志:

[Purchases] - DEBUG: No cached purchaser info, fetching

[Purchases] - DEBUG: there are no requests currently running, starting request GET 

[Purchases] - DEBUG: GET /v1/subscribers/$RCAnonymousID:f68c1e27ec9548489acd081bbf178ebe

[Purchases] - DEBUG: GET /v1/subscribers/$RCAnonymousID:f68c1e27ec9548489acd081bbf178ebe/offerings

[Purchases] - DEBUG: GET /v1/subscribers/$RCAnonymousID:f68c1e27ec9548489acd081bbf178ebe/offerings 200

[Purchases] - DEBUG: Requesting products with identifiers: {(

[Purchases] - DEBUG: Products request finished

[Purchases] - DEBUG: Valid Products:

[Purchases] - DEBUG: 2567531 - <SKProduct: 0x281753720>

[Purchases] - DEBUG: com.colorfulNightLight.unlockAllFeatures - <SKProduct: 0x281753740>

[Purchases] - DEBUG: Invalid Product Identifiers - (

[Purchases] - DEBUG: 1 completion handlers waiting on products

[Purchases] - DEBUG: GET /v1/subscribers/$RCAnonymousID:f68c1e27ec9548489acd081bbf178ebe 201

[Purchases] - DEBUG: Sending latest purchaser info to delegate

[Purchases] - DEBUG: serial request done: GET /subscribers/$RCAnonymousID%3Af68c1e27ec9548489acd081bbf178ebe, 0 requests left in the queue

[Purchases] - DEBUG: Vending offerings from cache

[Purchases] - DEBUG: Vending offerings from cache

[Purchases] - DEBUG: Vending purchaserInfo from cache

[Purchases] - DEBUG: Vending purchaserInfo from cache

[Purchases] - DEBUG: applicationDidBecomeActive

[Purchases] - DEBUG: Vending offerings from cache

[Purchases] - DEBUG: Vending offerings from cache

[Purchases] - DEBUG: makePurchase

[Purchases] - DEBUG: makePurchase - com.colorfulNightLight.unlockAllFeatures - Offering: Default

[Purchases] - DEBUG: PaymentQueue updatedTransaction: com.colorfulNightLight.unlockAllFeatures (null) ((null)) (null) - 0

[Purchases] - DEBUG: applicationDidBecomeActive

[Purchases] - DEBUG: applicationDidBecomeActive

[Purchases] - DEBUG: PaymentQueue updatedTransaction: com.colorfulNightLight.unlockAllFeatures 4 ((null)) 0 - 1

[Purchases] - DEBUG: Loaded receipt from file:///private/var/mobile/Containers/Data/Application/3C217C29-CDCE-4EBF-966C-
7ADB8B64CF1C/StoreKit/sandboxReceipt

[Purchases] - INFO: found 0 unsynced attributes for appUserID: $RCAnonymousID:f68c1e27ec9548489acd081bbf178ebe

[Purchases] - DEBUG: there are no requests currently running, starting request POST /receipts

[Purchases] - DEBUG: POST /v1/receipts

[Purchases] - DEBUG: POST /v1/receipts 400

[Purchases] - ERROR: The receipt is not valid.

[Purchases] - DEBUG: serial request done: POST /receipts, 0 requests left in the queue

[Purchases] - DEBUG: Finishing com.colorfulNightLight.unlockAllFeatures 4 (0)

[Purchases] - DEBUG: PaymentQueue removedTransaction: com.colorfulNightLight.unlockAllFeatures 4 (0 (null)) (null) - 1

[Purchases] - DEBUG: Vending offerings from cache

[Purchases] - DEBUG: makePurchase

[Purchases] - DEBUG: makePurchase - com.colorfulNightLight.unlockAllFeatures - Offering: Default

[Purchases] - DEBUG: PaymentQueue updatedTransaction: com.colorfulNightLight.unlockAllFeatures (null) ((null)) (null) - 0

[Purchases] - DEBUG: applicationDidBecomeActive

[Purchases] - DEBUG: applicationDidBecomeActive

标签: iosreact-nativein-app-purchaserevenuecat

解决方案


从日志中,您400 error The receipt is not valid.在发送到 RevenueCat 时会收到一个。这是发生在模拟器还是物理设备上?

要在模拟器(iOS 14+)上进行测试,您需要在 XCode 中创建 StoreKit 配置并将您的证书上传到 RevenueCat:https ://docs.revenuecat.com/docs/apple-app-store#ios-14-only -在模拟器上测试

在物理设备上,您无需进行任何额外设置即可测试购买。

您的沙盒帐户也可能已损坏,您可以尝试在 App Store Connect 中创建新的沙盒用户。


推荐阅读