Most basic steps for purchasing or subscribing a user to an IAP

suggest change

Assuming you know the productID:

First

import StoreKit

Then in your code

let productID: Set<NSObject> = ["premium" as NSObject]
let request = SKProductsRequest(productIdentifiers: productID)
request.delegate = self
request.start()

and in the SKProductsRequestDelegate:

func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
    if response.products.count > 0 {
        let product = response.products[0]
        let payment = SKPayment(product: product)
        SKPaymentQueue.defaultQueue().addPayment(payment)
    }
}

This is Swift 2 (defaultQueue() and didReceiveResponse). The class must adopt SKProductsRequestDelegate. Adding a payment does not finish the purchase: an SKPaymentTransactionObserver has to handle updatedTransactions and call finishTransaction. This page does not show that observer.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents