Most basic steps for purchasing or subscribing a user to an IAP
suggest changeAssuming 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents