Skip to content
tezvyn:
Menu

StoreKit

Source: developer.apple.comMediumHow cards are made

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.

A 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.

Interview question

In StoreKit 2, why should an app check Transaction.currentEntitlements at launch instead of relying only on a locally stored purchase flag?

  • a.Because locally stored flags are not encrypted and Apple rejects apps that store purchase state on disk
  • b.Because Transaction.currentEntitlements is required to calculate Apple's commission correctly
  • c.Because entitlements can change outside the app, such as a refund or a restore on a new device, and only Apple's data reflects thatCorrect
  • d.Because local flags are deprecated in iOS 17 and will stop working in a future release
Why?

Purchase state can change outside the app's control, a refund, family sharing, or a fresh install on another device, so only Apple's live entitlement data is trustworthy. Local flags are not inherently insecure or deprecated, they are just an unreliable single source of truth.

Just read this? Test yourself on what you have been reading.

Read the original → developer.apple.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on ios — each one lists the topics its interview covers.

See open roles