【问题标题】:RevenueCat display priceRevenueCat 显示价格
【发布时间】:2022-01-02 11:56:56
【问题描述】:

我有以下代码:

function Paywall({ onPress }) {

const getPrice = async () => {
    try {
        const offerings = await Purchases.getOfferings();
        if (offerings.current !== null && offerings.current.availablePackages.length !== 0) {
            console.log("OFFERING");
            console.log(offerings.current.monthly);
        }
    } catch (e) {
        console.log(e);
    }

    return offerings
}

useEffect(() => {
    getPrice()
})

return (
    <View style={styles.container}>
        <View style={styles.priceContainer}>
            <Text style={styles.headerText}>£9.99</Text>
            <Text style={styles.perMonthText}>per month</Text>
        </View>
        <View style={styles.buttonContainer}>
            <TouchableOpacity style={styles.button} onPress={onPress}>
                <Text style={styles.buttonText}>Subscribe for £9.99 / month</Text>
            </TouchableOpacity>
        </View>
    </View>
  );
}

我的日志正在恢复:

{"identifier": "$rc_monthly", "offeringIdentifier": "sale", "packageType": "MONTHLY", "product": {"currency_code": "GBP", "description": "All Access", "discounts": null, "identifier": "app_499_1m", "introPrice": {"cycles": null, "period": null, "periodNumberOfUnits": null, "periodUnit": null, "price": null, "priceString": null}, "intro_price": null, "intro_price_cycles": null, "intro_price_period": null, "intro_price_period_number_of_units": null, "intro_price_period_unit": null, "intro_price_string": null, "price": 11.99, "price_string": "£11.99", "title": "All Access (App NAME)"}}

如何在我的&lt;Text&gt; 中显示price_string

<Text style={styles.headerText}>£9.99</Text>

【问题讨论】:

  • 你的 price_string 是在哪里定义的?
  • @MWO price_string 来自offerings.current.monthly
  • 这里有什么问题?

标签: reactjs react-native revenuecat


【解决方案1】:

您必须确保它已定义,然后访问密钥:

<Text style={styles.headerText}>{offerings?.current?.monthly?.product?.price_string}</Text>

【讨论】:

    猜你喜欢
    • 2021-10-04
    • 1970-01-01
    • 2016-03-29
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    相关资源
    最近更新 更多