Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A lightweight StoreKit2 wrapper designed specifically for SwiftUI, making it easier to implement in-app purchases.

License

NotificationsYou must be signed in to change notification settings

jaywcjlove/StoreKitHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Usingmy app is also a way tosupport me:
KeyzerVidwall HubVidCropVidwallMousio HintMousioMusicerAudioerFileSentinelFocusCursorVideoerKeyClickerDayBarIconedMousioQuick RSSQuick RSSWeb ServeCopybook GeneratorDevTutor for SwiftUIRegexMateTime PassageIconize FolderTextsound SaverCreate Custom SymbolsDevHubResume RevisePalette GeniusSymbol Scribe

StoreKit Helper

中文

A lightweight StoreKit2 wrapper designed specifically for SwiftUI, making it easier to implement in-app purchases.

StoreKit Helper

Documentation

Please refer to the detailedStoreKitHelperdocumentation inDevTutor, which includes multiple quick start examples, custom payment interface examples, and API references, providing comprehensive examples and guidance.

Usage

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}}

filteredProducts

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}

License

Licensed under the MIT License.


[8]ページ先頭

©2009-2025 Movatter.jp