React Native - Use fallback paywalls
Follow the instructions below to use the fallback paywalls in your mobile app code.
For Android
-
Place the fallback file you downloaded in the Adapty Dashboard to a directory on the native layer. There are 2 correct directories to put the file:
android/app/src/main/assets/
orandroid/app/src/main/res/raw/
.
Please keep in mind that theres/raw
folder has a special file naming convention (start with a letter, no capital letters, no special characters except for the underscore, and no spaces in the names).- For android/app/src/main/assets/: Pass the file path relatively to the
assets
directory, for example:{ relativeAssetPath: 'android_fallback.json' }
if you placed the file to the root ofassets
itself{ relativeAssetPath: '<additional_folder>/android_fallback.json' }
if you placed it in a child folder ofassets
- For android/app/src/main/res/raw/: Pass
{ rawResName: 'android_fallback' }
. Type the file name without the file extension.
- For android/app/src/main/assets/: Pass the file path relatively to the
-
Pass the result of step 2 to the
android
property ofFallbackPaywallsLocation
.
For iOS
- In XCode, use the menu File -> Add Files to "YourProjectName" to add the fallback file you downloaded in the Adapty Dashboard.
- Pass
{ fileName: 'ios_fallback.json' }
to theios
property ofFallbackPaywallsLocation
.
Here's an example of retrieving fallback paywall data from locally stored JSON files named android_fallback.json
and ios_fallback.json
.
Current (v2.11+)
//after v2.11
const paywallsLocation = {
ios: {
fileName: 'ios_fallback.json'
},
android: {
//if the file is located in 'android/app/src/main/assets/'
relativeAssetPath: 'android_fallback.json'
}
}
await adapty.setFallbackPaywalls(paywallsLocation);
Legacy (before v2.11)
//Legacy (before v2.11)
const fallbackPaywalls = Platform.select({
ios: require('./ios_fallback.json'),
android: require('./android_fallback.json'),
});
// React Native automatically parses JSON, but we do not need that
const fallbackString = JSON.stringify(fallbackPaywalls);
await adapty.setFallbackPaywalls(fallbackString);
Parameters:
Parameter | Description |
---|---|
paywallsLocation | The object represents the location of the file resource. |