Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Magic Weather SwiftUI - RevenueCat Sample
Magic Weather is a sample app demonstrating the proper methods for using RevenueCat's Purchases SDK. This sample uses only native platform components - no third-party SDKs other than the Purchases SDK.
Sign up for a free RevenueCat account here.
Requirements
This sample uses:
- SwiftUI
- Xcode 14.0
- iOS 15.0
- Swift 5
See minimum platform version requirements for RevenueCat's Purchases SDK here.
Features
| Feature | Sample Project Location |
|---|---|
| 🕹 Configuring the Purchases SDK | Lifecycle/MagicWeatherApp.swift |
| 💰 Building a basic paywall | Views/PaywallView.swift |
| 🔐 Checking subscription status | Views/WeatherView.swift |
| 🤑 Restoring transactions | Views/UserView.swift |
| 👥 Identifying the user | ViewModels/UserViewModel.swift |
| 🚪 Logging out the user | ViewModels/UserViewModel.swift |
Setup & Run
Prerequisites
- Be sure to have an Apple Developer Account.
- You must join the Apple Developer Program to create In-App Purchases.
- You must sign the Paid Applications Agreement and complete your bank/tax information to test In-App Purchases.
- Be sure to set up a Sandbox Tester Account for testing purposes.
- Add your App-Specific Shared Secret to RevenueCat. If you don't have a RevenueCat account yet, sign up for free here.
- Be sure to set up at least one subscription on the App Store and link it to RevenueCat:
- Add the product (e.g.
rc_3999_1y) to RevenueCat's dashboard. It should match the product ID on the App Store. - Attach the product to an entitlement, e.g.
premium. - Attach the product to a package (e.g.
Annual) inside an offering (e.g.saleordefault).
- Add the product (e.g.
- If you're testing on a simulator instead of a physical device, be sure to set up your StoreKit configuration files.
- Get your API key from your RevenueCat project.
Steps to Run
-
Open the file
Magic Weather SwiftUI.xcodeprojin Xcode. -
On the General tab of the project editor, match the bundle ID to your bundle ID in App Store Connect and RevenueCat.
-
On the Signing & Capabilities tab of the project editor, select the correct development team from the Team dropdown.
-
In the
Constants.swiftfile:- Replace the value for
apiKeywith the API key from your RevenueCat project. - Replace the value for
entitlementIDwith the entitlement ID of your product in RevenueCat's dashboard. - Comment out the error directives.
- Replace the value for
-
Build the app and run it on your device.
Example Flow: Purchasing a Subscription
- On the home page, select Change the Weather.
- On the prompted payment sheet, select the product listed.
- On the next modal, select Subscribe.
- On the next modal, sign in with your Sandbox Apple ID.
- On the next modal, select Ok.
- Return to the home page and select Change the Weather to see the weather change!
Purchase Flow Demo
Support
For more technical resources, check out our documentation.
Looking for RevenueCat Support? Visit our community.