iOS 購買/訂閱用戶到IAP的最基本步驟


假設你知道productID

第一

import StoreKit

然後在你的代碼中

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

並在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)
    }
}