我正在使用 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