How to Add Subscriptions and Free Trials to a Flutter iOS App With RevenueCat
· 20 min read
We recently added paid subscriptions with a free trial to our Flutter app on the App Store, with RevenueCat handling the billing. Users pick a monthly or yearly plan, start with a free trial, and only get charged if they keep the subscription after the trial ends.
Most of the work wasn't in the Flutter code. It was in App Store Connect, the Apple Developer account and RevenueCat's dashboard, and a couple of those steps failed with errors that pointed somewhere other than the real cause. This article goes through every step on the Apple side in the order we did them, including the two problems that held us up:
- An Apple agreement nobody had accepted, which stopped us from signing the release build.
- An upload that App Store Connect rejected because the version number had already been approved.
This article only covers the App Store. The Flutter code works the same way on Google Play, but the store setup there is different, so I've covered it in a companion article for Google Play.
Before you start, you'll need:
- A paid Apple Developer Program membership, and access to the Account Holder, because some steps can only be done by them.
- Your app already created in App Store Connect.
- A RevenueCat account. The free tier is enough to get started.
- A Mac with Xcode, and a Flutter app that already builds for iOS.
- An iPhone for testing sandbox purchases.
Three systems are involved. The App Store takes the money, RevenueCat keeps track of who has paid, and your app asks RevenueCat whether to unlock the paid features.
- StoreKit is Apple's purchase system. It shows the payment sheet, charges the user's Apple account, runs the free trial and renews the subscription. You set up what it sells in App Store Connect.
- RevenueCat sits between the App Store and your app. It checks every purchase with Apple, tracks each subscriber's state (in trial, active, cancelled or expired), and gives your app a single answer: does this user have access?
- Your app uses RevenueCat's Flutter SDK,
purchases_flutter, to show the plans, start a purchase and read that answer.
How the app, the App Store and RevenueCat work together
Notice that the app never asks Apple whether a user has paid. It asks RevenueCat, which has already checked with Apple and also receives Apple's server notifications about renewals and cancellations.
You could use StoreKit directly, but then you'd also need your own server to verify purchases and receive those renewal and cancellation messages. RevenueCat does that part for you, and the same app code works on Google Play.
RevenueCat uses three terms that come up throughout this article:
| Term |
What it is |
Our example |
| Product |
One subscription Apple sells, with a price and a length |
pro_monthly, pro_yearly |
| Entitlement |
The access a product unlocks. The app checks this, never the product |
pro |
| Offering |
The set of products your paywall shows, grouped into packages. You can change it from the dashboard without releasing a new version |
Monthly and Annual packages |
Your app should always check the entitlement, not the product. That way, if you add a new plan later, the app code doesn't change, because the new product unlocks the same entitlement.
Apple won't sell anything on your behalf until the right agreements are signed. Two different agreements matter, and either one can block you without a clear error.
This is the agreement that allows you to sell. Without it, your subscriptions never load in the app, even during testing, and you don't get an error message. The paywall is just empty.
- In App Store Connect, open Business. Older accounts call it Agreements, Tax, and Banking.
- Check that the Paid Apps agreement shows as Active.
- If it doesn't, the Account Holder has to accept it and then fill in the bank account and tax forms. The agreement becomes active once Apple has processed them.
Apple updates the Apple Developer Program License Agreement from time to time, and the Account Holder has to accept each new version. Until they do, Apple blocks some actions for everyone on the team.
We found this out when flutter build ipa built the app archive but then failed to export it:
error: exportArchive Unable to process request - PLA Update available
error: exportArchive No signing certificate "iOS Distribution" found
The second line looks like a certificate problem, but the first line is the real cause. While the agreement isn't accepted, Xcode can't create or download the distribution certificate it needs to sign the app.
To fix it, the Account Holder signs in at developer.apple.com/account and accepts the agreement shown in the banner. Once they did that, the same flutter build ipa --release command worked.
So check both agreements before you start. If the Account Holder is someone else at your company, ask them now, not on release day.
On the App Store, subscriptions live inside a subscription group, and a free trial is set up as an introductory offer on each subscription.
A subscription group holds plans that replace each other. A user can only have one active subscription per group, so if you put the monthly and yearly plans in the same group, switching between them counts as an upgrade or downgrade instead of a second subscription. The group also decides free trial eligibility: a user gets one introductory offer per group.
In App Store Connect, open your app and go to Monetization → Subscriptions.
- Create a subscription group. Give it a reference name, such as
Pro, and add a localized display name, which users see when they manage their subscriptions.
- Create a subscription in that group and enter:
- Reference name: only your team sees this, for example
Pro Monthly.
- Product ID: for example
pro_monthly. You can't change it later, and you can't reuse it even if you delete the subscription.
- Set the duration (1 month) and the price. Pick a price for your main country, and Apple fills in the other countries. You can adjust any of them.
- Add a localization with a display name and description. Users see these on the payment sheet.
- Add the review information: a screenshot of your paywall, plus notes for the reviewer if anything needs explaining. Apple won't review the subscription without the screenshot.
- Repeat these steps for the yearly plan in the same group.
Inside the group, you rank the subscriptions by level. If your plans give the same access and only the billing period differs, Apple's guidance is to put them on the same level.
- Open a subscription and go to its Subscription Prices section.
- Click +, then Create Introductory Offer.
- Choose the countries, a start date, and no end date.
- Set the type to Free and pick the length, for example 1 week.
- Repeat for the other subscription.
You don't need to write any code to decide who gets the trial. Apple only shows it to users who haven't had an introductory offer in that group before, and the RevenueCat SDK applies it automatically.
Your first subscriptions have to be reviewed together with a new version of the app. Once each subscription shows Ready to Submit, open the app version you're about to submit, find the In-App Purchases and Subscriptions section, and add them there. After that first approval, you can submit new subscriptions on their own.
RevenueCat needs to talk to Apple for three different reasons: to verify purchases, to read your product list, and to hear about renewals and cancellations. Each one has its own setup.
In your RevenueCat project, add an App Store app and enter your app's bundle ID exactly as it appears in App Store Connect, for example com.example.app. RevenueCat then gives you a public API key that starts with appl_, which you'll use in Step 5.
- In App Store Connect, go to Users and Access → Integrations → In-App Purchase.
- Generate a key. Download the
.p8 file, and note the Key ID and the Issuer ID shown on the page.
- In RevenueCat, open your App Store app's settings and upload the
.p8 file along with the Key ID and Issuer ID.
Apple only lets you download a .p8 file once, so store it somewhere safe, and never commit it to your repository.
This key lets RevenueCat read your subscriptions from App Store Connect, so you don't have to type product IDs by hand.
- Go to Users and Access → Integrations → App Store Connect API → Team Keys.
- Generate a key with the App Manager role and download its
.p8 file.
- Upload it on the same RevenueCat settings page, with its Key ID and the Issuer ID.
Apple can send RevenueCat a message whenever a subscription renews, gets cancelled, fails to bill, or converts from a trial to paid. Without these notifications, RevenueCat only finds out the next time the app checks in.
- In RevenueCat's App Store app settings, copy the Apple Server Notification URL.
- In App Store Connect, open your app, go to App Information, and find App Store Server Notifications.
- Paste the URL for both Production and Sandbox, and choose Version 2.
RevenueCat's dashboard shows when it last received a notification, so you can confirm this is working while you test.
- In RevenueCat, go to Products and import your App Store subscriptions.
- Open Entitlements, create one (we called ours
pro), and attach both products to it. If you skip this, a purchase charges the user but unlocks nothing.
- Open Offerings and create an offering with a Monthly (
$rc_monthly) and an Annual ($rc_annual) package, then pick the App Store product for each one.
- Mark the offering as Current. This is the offering the app loads, and you can switch to a different one later without a new release.
If you also sell on Google Play, reuse the same entitlement and offering, and add the Play products to the same packages.
The iOS app needs the In-App Purchase capability, and its bundle ID has to match App Store Connect exactly.
- Open
ios/Runner.xcworkspace in Xcode. Make sure it's the .xcworkspace and not the .xcodeproj, so the CocoaPods dependencies load.
- Select the Runner target and open Signing & Capabilities.
- Click + Capability and add In-App Purchase.
- Check that the Bundle Identifier matches the one you entered in App Store Connect and RevenueCat.
Next, add the RevenueCat packages to pubspec.yaml. These are the versions we used; check pub.dev for the current ones:
dependencies:
purchases_flutter: ^10.13.2
purchases_ui_flutter: ^10.13.2
Then install them and the iOS pods:
flutter pub get
cd ios && pod install
If pod install complains about the minimum iOS version, raise the platform :ios line in ios/Podfile to the version the RevenueCat SDK asks for.
This code is shared between iOS and Android, so I'll go through the whole flow and point out the parts that are specific to iOS.
We keep one key per store in .env files, loaded with flutter_dotenv:
REVENUECAT_API_KEY_TEST=test_...
REVENUECAT_API_KEY_IOS=appl_...
REVENUECAT_API_KEY_ANDROID=goog_...
A small config class picks the key for the current build:
class SubscriptionConfig {
static const entitlementId = 'pro';
static const offeringId = 'pro'; // fallback if no offering is marked Current
static const enforced = bool.fromEnvironment(
'SUBSCRIPTIONS_ENFORCED',
defaultValue: true,
);
// Debug builds use RevenueCat's Test Store unless told otherwise.
// Release builds never do: the SDK crashes on a test key in release.
static const useTestStore =
kDebugMode && !bool.fromEnvironment('DISABLE_TEST_STORE');
static String get apiKey {
if (useTestStore) return dotenv.env['REVENUECAT_API_KEY_TEST'] ?? '';
return Platform.isIOS
? dotenv.env['REVENUECAT_API_KEY_IOS'] ?? ''
: dotenv.env['REVENUECAT_API_KEY_ANDROID'] ?? '';
}
static bool get hasUsableKey => isUsableKey(apiKey, useTestStore);
static bool isUsableKey(String key, bool testStore) {
if (testStore) return key.isNotEmpty;
return key.startsWith('appl_') || key.startsWith('goog_');
}
}
We start RevenueCat once, when the app launches. If subscriptions are turned on but there's no usable key, the app throws an error instead of showing a paywall that can never load:
Future<void> configure() async {
if (!SubscriptionConfig.hasUsableKey) {
if (SubscriptionConfig.enforced) {
throw StateError('Subscriptions are on but no usable RevenueCat key was found.');
}
return;
}
await Purchases.setLogLevel(kDebugMode ? LogLevel.debug : LogLevel.warn);
await Purchases.configure(PurchasesConfiguration(SubscriptionConfig.apiKey));
Purchases.addCustomerInfoUpdateListener(_onCustomerInfo);
}
We also have a test that reads .env.prod and fails if the appl_ key is missing. That way, a missing key shows up when the tests run, before anyone makes a release build.
The rest of the flow uses a handful of SDK calls:
- After the user signs in, call
Purchases.logIn(userId) so their subscription follows them to other devices, and call Purchases.logOut() when they sign out.
- Load
offerings.current and pass it to PaywallView from purchases_ui_flutter, which draws the paywall you design in RevenueCat's dashboard.
- Gate the app on the entitlement with
customerInfo.entitlements.all['pro']?.isActive. We let users in for up to 72 hours when we can't reach RevenueCat or our own server, but never when we know the subscription has expired.
- Add a Restore Purchases button that calls
Purchases.restorePurchases() and always shows the user a result. Apple requires a way to restore purchases (more on that in Step 7).
TestFlight builds are release builds. Our app uses .env.prod in release builds and .env.dev in debug builds. Since a TestFlight build is a release build, it would point at production. To send a TestFlight build to our staging server instead, we pass an override:
flutter build ipa --release --dart-define=ENV=dev
Purchases in TestFlight still go through Apple's sandbox, so nobody gets charged either way.
Check that the trial actually loaded. If the trial is set up wrong, the paywall still shows the plans, just without the trial, which is easy to miss. We added a debug-only screen that prints each product's price and introductory offer:
final intro = package.storeProduct.introductoryPrice;
final offer = intro == null
? 'NO INTRO OFFER'
: 'intro ${intro.priceString} ${intro.periodNumberOfUnits}${intro.periodUnit.name}';
If you see NO INTRO OFFER, either the free trial isn't set up for that product, or it isn't available in the store country of the account you're testing with. Whether a particular user can still get the trial is a separate question, and the SDK answers it with Purchases.checkTrialOrIntroductoryPriceEligibility.
There are three ways to test, and we used each one at a different stage:
| Where |
What it tests |
Charges real money |
Needs App Store Connect set up |
| RevenueCat Test Store |
Your app's purchase flow and paywall |
No |
No |
| Apple sandbox (debug build on a device) |
Real StoreKit, with your real products and trial |
No |
Yes |
| TestFlight |
The exact build you'll ship |
No |
Yes |
The Test Store is a fake store run by RevenueCat. Our debug builds use it by default, so any developer can tap through the paywall and make a purchase without an Apple account or a finished App Store Connect setup. To use it, create Test Store products in RevenueCat and add them to the same packages in your offering.
It doesn't test anything on Apple's side, though, so it can't tell you whether your real products, prices or trial are set up correctly.
Sandbox purchases use your real products and trial, but nobody is charged.
-
In App Store Connect, go to Users and Access → Sandbox and create a test account. Use an email address that has never been used for a real Apple Account.
-
On your iPhone, sign in to that account in the sandbox section of the App Store settings. You can leave your normal Apple Account signed in.
-
Run a debug build with the Test Store turned off, so the app talks to StoreKit:
flutter run --dart-define=DISABLE_TEST_STORE=true
-
Buy a plan. The payment sheet shows [Environment: Sandbox], which confirms you won't be charged.
Time moves faster in the sandbox. With Apple's default settings, a 1-week trial or billing period lasts about 3 minutes, a month about 5 minutes, and a year about an hour. You can change the renewal speed for each sandbox account in App Store Connect.
A sandbox account can only use the free trial once per subscription group. To test the trial again, open the account under Sandbox in App Store Connect and clear its purchase history, or create a new sandbox account.
Before each release, we install the actual release build from TestFlight and buy a plan again. TestFlight purchases are free and also renew faster than real time. This is how you catch problems that only appear in release builds, like a missing appl_ key in .env.prod.
In the sandbox or TestFlight, the paywall should show both plans with the free trial, and buying a plan should unlock the app straight away. In RevenueCat's dashboard, the customer shows up with a trial status, and you can see that a server notification arrived. Leave it for a few minutes and you'll see the trial convert to paid and then renew. Cancelling in the device's subscription settings should also show up in RevenueCat, and Restore Purchases should bring the subscription back after you delete and reinstall the app.
If the paywall is empty, check these in order: the Paid Apps agreement is active, the subscriptions are attached to the offering, the offering is marked Current, and the bundle ID matches everywhere.
Apple reviews subscription apps closely, and most rejections come from information missing from the paywall. Section 3.1.2 of the App Review Guidelines covers subscriptions.
Before submitting, make sure your paywall makes it clear what the user gets, and shows each plan's price and billing period, for example "$X.XX per month". The free trial should say how long it lasts and what the user pays when it ends, and the paywall should say that the subscription renews automatically until the user cancels. It also needs working links to your Terms of Use and Privacy Policy, and a Restore Purchases button.
The App Store listing needs the same links:
- Add your Privacy Policy URL in the app's App Privacy section.
- For the Terms of Use, either use Apple's standard license agreement and link to it in your app description, or add your own under License Agreement in App Information.
A few more things help the review go smoothly:
- Give the reviewer a test account in the review notes if your app needs a login before the paywall.
- Let users delete their account inside the app if they can create one there. Apple requires this for any app with sign-up, and reviewers check it.
- Make sure the reviewer can reach the paywall from a fresh install, and explain in the review notes how to get there.
RevenueCat's paywall templates already show the price, billing period and trial for each plan. You can add your terms and privacy links in the paywall editor, or add them below the paywall in your own code, which is what we did.
Flutter sets both of the iOS version numbers from the version line in pubspec.yaml:
version: 1.2.0+17
| Part |
iOS name |
Shown to users |
Rule |
1.2.0 |
Version (CFBundleShortVersionString) |
Yes |
Must be higher than the last approved version |
17 |
Build (CFBundleVersion) |
No |
Must be new for that version |
We learned the first rule from this upload error:
This bundle is invalid. The value for key CFBundleShortVersionString [1.1.0]
in the Info.plist file must contain a higher version than that of the
previously approved version [1.1.0]. (90062)
Invalid Pre-Release Train. The train version '1.1.0' is closed for new
build submissions (90186)
Version 1.1.0 had already been approved, so Apple had "closed" it, which means no more builds can be uploaded under that version, not even for TestFlight. Raising the build number on its own doesn't help. We changed the version to 1.2.0, since subscriptions are a new feature anyway, and rebuilt.
In App Store Connect, you also need to add the new version to the app (the + next to iOS App) before you can submit it for review. TestFlight accepts the build before you do that.
flutter build ipa --release
The signed .ipa ends up in build/ios/ipa/. You can upload it with Apple's Transporter app by dragging the file in, or open build/ios/archive/Runner.xcarchive in Xcode and choose Distribute App → App Store Connect.
Before you submit the version for review, install that exact build from TestFlight and buy a plan one more time. It's the only test that runs with your production .env file and the real appl_ key.
If we were starting over, these are the things we'd want to know on day one:
- Check the agreements first. An unaccepted agreement shows up as a certificate error or an empty paywall, and neither one points at the real cause.
- Plan the version number before you upload. Once a version is approved, it's closed, so a feature release needs a new version number, not just a new build.
- Check the entitlement, not the product. That keeps the app code the same when your plans change.
- Test in three layers. Use the Test Store for app logic, the sandbox for your real products, and TestFlight for the build you're going to ship.
- Remember the trial eligibility rule. One free trial per user per subscription group explains most of the "why don't I see the trial?" questions you'll get during testing.