-
Notifications
You must be signed in to change notification settings - Fork 0
iOS
Roman Karpievich edited this page Apr 26, 2019
·
13 revisions
- Purchases
- Verification
finishing stands for whether transaction will be finished automatically or not.
BillingHelper.sharedInstance.products(["com.applicaster.iap.purchase1"]) { (result) in
switch result {
case .success(let response):
let products = response.products
let invalidIDs = response.invalidIDs
case .failure(let error):
print(error.localizedDescription)
}
}BillingHelper.sharedInstance.purchase(product, amount: 1, finishing: true, completion: { (result) in
switch result {
case .success(let purchase):
self.unlockContent(for: purchase)
case .failure(let error):
print(error.localizedDescription)
}
})BillingHelper.sharedInstance.restore(finishing: true) { (result) in
switch result {
case .success(let transactions):
let purchasedItemIDs = transactions.map({ $0.payment.productIdentifier })
case .failure(let error):
print(error.localizedDescription)
}
}It is possible to set associated downloadable content to in-app purchase. This content can be retrieved through SkPaymentTransaction object which you get during purchasing, restoration and finishing uncompleted transactions.
let transaction = purchase.transaction!
let downloads = transaction.downloads
BillingHelper.sharedInstance.start(downloads)
//BillingHelper.sharedInstance.cancel(downloads)
//BillingHelper.sharedInstance.pause(downloads)
//BillingHelper.sharedInstance.resume(downloads)
BillingHelper.sharedInstance.downloadsCompletion = { downloads in
// process downloaded content
}It is possible that transaction won’t be finished (for example due to network connection issues). It is recommended to set your transaction completion handler at application(:didFinishLaunchingWithOptions:) method.
BillingHelper.sharedInstance.unfinishedTransactionCompletion = { transaction in
switch transaction.transactionState {
case .purchased, .restored:
// unlock content
BillingHelper.sharedInstance.finishTransaction(transaction)
case .deferred,.failed, .purchasing:
break
}
}let receiptData: Data? = BillingHelper.sharedInstance.localReceiptData()BillingHelper.sharedInstance.refreshReceipt { (result) in
switch result {
case .success:
break
case .failure(let error):
print(error.localizedDescription)
}
}