React Native Purchases is a cross platform solution for in-app subscription. A backend is also provided via RevenueCat
$ npm install react-native-purchases --save
$ react-native link react-native-purchases
Purchases.framework also needs to be added to your iOS project. The npm install will download the correct framework version.
Alternatively you can install the framework via CocoaPods.
- Copy
Purchases.framework
from theRNPurchases
sub-project and create a reference in the outer project
- In Xcode, in project manager, select your app target.
- Select the general tab
- Drag
Purchases.framework
from your project to the Embedded Binaries section - Add
$(PROJECT_DIR)/../node_modules/react-native-purchases/ios
to Framework Search paths in build settings
The App Store, in it's infinite wisdom, still rejects fat frameworks, so we need to strip our framework before it is deployed. To do this, add the following script phase to your build.
- In Xcode, in project manager, select your app target.
- Open the
Build Phases
tab - Add a new
Run Script
, name itStrip Frameworks
- Add the following command
"${PROJECT_DIR}/../node_modules/react-native-purchases/ios/strip-frameworks.sh"
(quotes included)
import Purchases from 'react-native-purchases';
Purchases.setup("revenuecat_api_key", "app_user_id", (productIdentifier, purchaserInfo, error) => {
if (error) {
this.setState({error: error.message});
return;
}
this.setState({purchaserInfo})
});
Purchases.getEntitlements().then((entitlements) => {
this.setState({entitlements})
Purchases.makePurchase(entitlements.pro.monthly.identifier);
});