Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9
A lightweight StoreKit2 wrapper designed specifically for SwiftUI, making it easier to implement in-app purchases.
License
jaywcjlove/StoreKitHelper
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A lightweight StoreKit2 wrapper designed specifically for SwiftUI, making it easier to implement in-app purchases.
Please refer to the detailedStoreKitHelperdocumentation inDevTutor, which includes multiple quick start examples, custom payment interface examples, and API references, providing comprehensive examples and guidance.
At the entry point of the SwiftUI application, create and inject aStoreContext instance, which is responsible for loading the product list and tracking purchase status.
import StoreKitHelperenumAppProduct:String,InAppProduct{case lifetime="focuscursor.lifetime"case monthly="focuscursor.monthly"varid:String{ rawValue}}@mainstructDevTutorApp:App{@StateObjectvarstore=StoreContext(products:AppProduct.allCases)varbody:someScene{WindowGroup{ContentView().environmentObject(store)}}}
UseStoreKitHelperView to directly display an in-app purchase popup view and configure various parameters through a chained API.
structPurchaseContent:View{@EnvironmentObjectvarstore:StoreContextvarbody:someView{StoreKitHelperView().frame(maxWidth:300).frame(minWidth:260) // Triggered when the popup is dismissed (e.g., user clicks the close button).onPopupDismiss{ store.isShowingPurchasePopup=false} // Sets the content area displayed in the purchase interface // (can include feature descriptions, version comparisons, etc.).pricingContent{AnyView(PricingContent())}.termsOfService{ // Action triggered when the [Terms of Service] button is clicked}.privacyPolicy{ // Action triggered when the [Privacy Policy] button is clicked}}}
Click to open the paid product list interface.
structPurchaseButton:View{@EnvironmentObjectvarstore:StoreContextvarbody:someView{if store.hasNotPurchased==true{PurchasePopupButton().sheet(isPresented: $store.isShowingPurchasePopup){ /// Popup with the paid product listPurchaseContent()}}}}
You can use thehasNotPurchased property inStoreContext to check if the user has made a purchase, and then dynamically display different interface content. For example:
@EnvironmentObjectvarstore:StoreContextvarbody:someView{if store.hasNotPurchased==true{ // 🧾 User has not purchased - Show restricted content or prompt for purchase}else{ // ✅ User has purchased - Show full features}}
This is a simple migration solution: the product list is filtered by product ID, retaining the old product IDs so existing users don’t need to repurchase and can restore their purchases, while new users purchase through the new product IDs, achieving a smooth transition.
enumAppProduct:String,InAppProduct{ /// oldcase sponsor="focuscursor.Sponsor"case generous="focuscursor.Generous" /// newcase monthly="focuscursor.monthly"case lifetime="focuscursor.lifetime"varid:String{ rawValue}}StoreKitHelperView().filteredProducts(){ productID, productinif productID==AppProduct.sponsor.rawValue{returnfalse}if productID==AppProduct.generous.rawValue{returnfalse}returntrue}StoreKitHelperSelectionView().filteredProducts(){ productID, productinreturntrue}
Licensed under the MIT License.
About
A lightweight StoreKit2 wrapper designed specifically for SwiftUI, making it easier to implement in-app purchases.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
