tezvyn:

StoreKit

AI-drafted, machine-checkedSource: developer.apple.comintermediate
StoreKit

StoreKit is Apple's framework for in-app purchases and subscriptions. It manages product lookup, presenting the payment sheet, processing transactions, and restoring purchases, so apps never touch raw payment data directly.

WHY IT EXISTS Apple requires that digital goods and subscriptions sold inside an iOS app go through Apple's payment system, both for security and because Apple takes a commission. Before StoreKit, developers had no sanctioned way to sell a subscription or unlock a feature without building custom payment infrastructure that Apple would reject at review. StoreKit exists as the one approved path: a framework that handles pricing, payment, tax, and receipts so every app follows the same rules.

THE MENTAL MODEL Think of StoreKit as a cash register that only Apple is allowed to operate. Your app chooses what is for sale, StoreKit rings it up, Apple handles the money and the receipt, and your app is handed back a signed proof of purchase it can trust without talking to a payment processor itself.

HOW IT WORKS You configure products, consumable, non consumable, or subscription, in App Store Connect with an identifier and price tier. At runtime, Product.products(for:) fetches those product objects, and calling purchase() on a Product presents Apple's system payment sheet. On success, StoreKit returns a Transaction wrapped in a VerificationResult, signed in Apple's JWS format, which you verify locally instead of calling a validation server. An app also listens to Transaction.updates, an async sequence that delivers renewals, refunds, and purchases restored from other devices.

WHEN IT MATTERS It matters the moment an app plans to charge for anything digital: unlocking pro features, subscriptions, or virtual currency. Get entitlement checks wrong, like trusting local state instead of Transaction.currentEntitlements, and users lose access after reinstalling, or worse, keep access after a refund. Ignoring Transaction.updates means missed cancellations and unhappy support tickets.

ONE CONCRETE EXAMPLE A meditation app sells a nine dollar monthly subscription. On launch it checks Transaction.currentEntitlements for an active subscription, unlocking premium sessions if found. When the user taps subscribe, purchase() shows Apple's sheet, the user authenticates with Face ID, and a verified transaction arrives, which the app finishes with transaction.finish() only after unlocking content.

Read the original → developer.apple.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.