I exploit the code under for a non-consumable in-app buy in my apps. Has anyone labored out deal with this with StoreKit 2 and UIKit? I’ve appeared over the Apple documentation and downloaded the pattern code however I am not seeing get there in UIKit.
SKPaymentQueue – deprecated
SKPayment – deprecated
SKProduct – deprecated
transactionState – deprecated
SKPaymentTransaction – deprecated
finishTransaction – deprecated
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment fee: SKPayment, for product: SKProduct) -> Bool
{
true
}
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])
{
for transaction in transactions
{
change transaction.transactionState
{
case .buying:
break
case .bought:
SKPaymentQueue.default().finishTransaction(transaction)
// Disguise the restore button
navigationItem.setRightBarButton(nil, animated: true)
// Set the ProVerion within the Db to true
IAPHandler.setProVersionToPurchased()
// Additionally cover the Buy button
UIView.animate(withDuration: 1.0, animations: { [weak self] in
self?.purchaseBtn_Outlet.alpha = 0
}) { [weak self] (success) in
if self!.theDevice.isOneOf(Okay.Device_Groups.SE_3_iPhone8) {
self?.segControlTop_Constraint.fixed = 10
} else if self!.theDevice.isPhone {
self?.segControlTop_Constraint.fixed = 30
}
}
case .failed:
if let error = transaction.error
{
let errorDescription = error.localizedDescription
print("Transaction failed as a consequence of error: (errorDescription)")
}
case .restored:
SKPaymentQueue.default().finishTransaction(transaction)
// Disguise the restore button
navigationItem.setRightBarButton(nil, animated: true)
// Set the ProVerion within the Db to true
IAPHandler.setProVersionToPurchased()
// Additionally cover the Buy button
UIView.animate(withDuration: 1.0, animations: { [weak self] in
self?.purchaseBtn_Outlet.alpha = 0
}) { [weak self] (success) in
if self!.theDevice.isOneOf(Okay.Device_Groups.SE_3_iPhone8) {
self?.segControlTop_Constraint.fixed = 10
} else if self!.theDevice.isPhone {
self?.segControlTop_Constraint.fixed = 30
}
}
case .deferred:
break
@unknown default:
if let error = transaction.error
{
let errorDescription = error.localizedDescription
print("Transaction failed as a consequence of error: (errorDescription)")
}
break
}
}
}
class IAPHandler: NSObject {
//Get the ProVersion Standing
static func isProVersionPurchased() -> Bool
{
let VC_String = "IAPHandler"
var theStatus = false
do {
let settings = attempt Database.shared.databaseConnection!.learn { db in
attempt My_Settings.fetchOne(db)
}
let theStatusText = settings?.ProVersion ?? "false"
theStatus = theStatusText == "true" ? true : false
} catch {
print("Getting the ProVersion Standing failed! (VC_String) (error)")
}
return theStatus
}
// Set ProVersion to true.
static func setProVersionToPurchased()
{
let VC_String = "IAPHandler"
do {
attempt Database.shared.databaseConnection!.write { db in
attempt db.execute(sql: "UPDATE My_Settings SET ProVersion = :proVersion WHERE Settings_ID = :id",
arguments: ["proVersion": "true", "id": 1])
}
} catch {
print("Replace set professional model, failed! (VC_String)s (error)")
}
}
}// Finish of sophistication