-
-
Save joshdholtz/3f26a6f06b86d2452d4180182876d824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from 'react'; | |
import { Platform, Text, View } from 'react-native'; | |
import Purchases, { PurchasesOffering } from 'react-native-purchases'; | |
const APIKeys = { | |
apple: "your_revenuecat_apple_api_key", | |
google: "your_revenuecat_google_api_key", | |
}; | |
export default function App() { | |
const [currentOffering, setCurrentOffering] = useState<PurchasesOffering | null>(null); | |
useEffect(() => { | |
const setup = async () => { | |
if (Platform.OS == "android") { | |
await Purchases.configure({ apiKey: APIKeys.google }); | |
} else { | |
await Purchases.configure({ apiKey: APIKeys.apple }); | |
} | |
const offerings = await Purchases.getOfferings(); | |
setCurrentOffering(offerings.current); | |
}; | |
Purchases.setDebugLogsEnabled(true); | |
setup() | |
.catch(console.log); | |
}, []); | |
if (!currentOffering) { | |
return "Loading..."; | |
} else { | |
return ( | |
<View> | |
<Text>Current Offering: {currentOffering.identifier}</Text> | |
<Text>Package Count: {currentOffering.availablePackages.length}</Text> | |
{ | |
currentOffering.availablePackages.map((pkg) => { | |
return <Text>{ pkg.product.identifier }</Text> | |
}) | |
} | |
</View> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Purchases.configure
is handled as a promise here, but the typescript typings shows it as having avoid
return type