About ‘PurchaseKit’
PurchaseKit is a solution to integrate in-app purchases into iOS
apps with just a few steps and most importantly, o ering you a
couple of great themes to select from, which will boost your in-
app purchase sales.
PurchaseKit.xcframework is the main framework that handles all
the con gurations, purchases, receipt validation and more. You
don’t need to write any code to handle in-app purchases
anymore, this framework will do the hard work for you.
PurchaseKit folder includes a few themes that will magically
present the in-app purchase products, with the price, trial period
and much more. You can easily edit these themes in SwiftUI.
Currently the framework supports only the following types of in-
app purchases:
fi
ff
How to Add ‘PurchaseKit’
TO YOUR APP
STEP #1:
Drag & Drop the PurchaseKit folder into your app Xcode project.
Then select your app’s target -> General and make sure you
select Embed & Sign for the PurchaseKit.xcframework
STEP #2:
Con gure the PurchaseKit framework with your in-app purchase
identi ers (Product ID) and App-Speci c Shared Secret.
See image below from App Store Connect, to understand where
to get your App-Speci c Shared Secret and In-App Purchase
IDs.
fi
fi
fi
fi
Make sure that the status for all Product IDs is “Ready to Submit”.
Now that you have you App-Speci c Shared Secret and Product
IDs. It’s time to con gure the PurchaseKit inside AppDelegate.
Open AppDelegate.swift in Xcode -> import PurchaseKit and
con gure the framework as shown below:
fi
fi
fi
Congratulations!
You have successfully integrated the PurchaseKit into your app.
Build & Run your app on a real device (not simulator).
You should see in Xcode Console the PurchaseKit logs:
✦ PurchaseKit ✦ - Requesting products with Identifiers:
✦ PurchaseKit ✦ - Found products
If you’ve setup everything correct on the App Store Connect,
then you will see the products with the identi er, title and price
exactly as you’ve set them on the ASC.
Found product
Identifier: monthly, Title: Monthly, Price: 1.99
How to Present iAP Screen
Your app should have a button or any other element that will
trigged the presentation of one of the PurchaseKit themes.
*** THE EXAMPLE BELOW IS FOR SWIFTUI - NOT SWIFT ***
For this example, let assume you have a ContentView.swift le
with a button and tapping it, will present the iAP (in-app
purchase) screen.
fi
fi
Have a @State boolean that will be toggled when the user taps
the button, then implement .sheet(isPresented:).
See the image example below:
See the demo app for more examples and details.
If you have an app that is built using Swift instead of SwiftUI, you
can use the PurchaseKit to present one of the iAP screens.
*** THE EXAMPLE BELOW IS FOR SWIFT - NOT SWIFT UI ***
For this example in Swift, you can easily call a function on the
PurchaseKit framework and pass the iAP screen (theme).
You can also use the UIHostingController yourself if you want to
present any SwiftUI view in Swift.
See the image example below:
Good job!
Now you know how to present the in-app purchase screen.
All purchases/restore purchases are happening via PurchaseKit
framework and the SwiftUI themes/views.
How to unlock content
Your app should always verify the receipt for auto-renewable
subscriptions, this way you can decide if you want to unlock the
new features/content for that user or lock everything if their
subscription expired.
Call the PKManager.verifySubscription function as soon as you
need to verify if a given subscription for a speci c Product ID is
still active or expired.
You can call this in viewDidLoad or on your screen where you
have content that needs to be locked/unlock via a subscription.
That’s all!
Please reach out to me for any questions you may have:
E-mail: support@apps4world.com
Skype: Apps4World
fi