Как настроить непотребляемую покупку в приложении в UIKit с помощью StoreKit 2IOS

Программируем под IOS
Ответить
Anonymous
 Как настроить непотребляемую покупку в приложении в UIKit с помощью StoreKit 2

Сообщение Anonymous »

Я использую приведенный ниже код для непотребляемых покупок в своих приложениях. Кто-нибудь придумал, как справиться с этим с помощью StoreKit 2 и UIKit? Я просмотрел документацию Apple и загрузил пример кода, но не понимаю, как это сделать в UIKit.
SKPaymentQueue — устарел

SKPayment — устарело

SKProduct — устарело

transactionState — устарело

SKPaymentTransaction — устарело

finishTransaction – устарел
func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool
{
true
}

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])
{
for transaction in transactions
{
switch transaction.transactionState
{
case .purchasing:
break

case .purchased:

SKPaymentQueue.default().finishTransaction(transaction)

// Hide the restore button
navigationItem.setRightBarButton(nil, animated: true)

// Set the ProVerion in the Db to true
IAPHandler.setProVersionToPurchased()

// Also hide the Purchase button
UIView.animate(withDuration: 1.0, animations: { [weak self] in
self?.purchaseBtn_Outlet.alpha = 0
}) { [weak self] (success) in

if self!.theDevice.isOneOf(K.Device_Groups.SE_3_iPhone8) {
self?.segControlTop_Constraint.constant = 10

} else if self!.theDevice.isPhone {
self?.segControlTop_Constraint.constant = 30
}
}

case .failed:
if let error = transaction.error
{
let errorDescription = error.localizedDescription
print("Transaction failed due to error: \(errorDescription)")
}

case .restored:

SKPaymentQueue.default().finishTransaction(transaction)

// Hide the restore button
navigationItem.setRightBarButton(nil, animated: true)

// Set the ProVerion in the Db to true
IAPHandler.setProVersionToPurchased()

// Also hide the Purchase button
UIView.animate(withDuration: 1.0, animations: { [weak self] in
self?.purchaseBtn_Outlet.alpha = 0
}) { [weak self] (success) in

if self!.theDevice.isOneOf(K.Device_Groups.SE_3_iPhone8) {
self?.segControlTop_Constraint.constant = 10

} else if self!.theDevice.isPhone {
self?.segControlTop_Constraint.constant = 30
}
}

case .deferred:
break

@unknown default:
if let error = transaction.error
{
let errorDescription = error.localizedDescription
print("Transaction failed due to error: \(errorDescription)")
}
break
}
}
}

class IAPHandler: NSObject {

//Get the ProVersion Status
static func isProVersionPurchased() -> Bool
{
let VC_String = "IAPHandler"
var theStatus = false

do {
let settings = try Database.shared.databaseConnection!.read { db in
try My_Settings.fetchOne(db)
}

let theStatusText = settings?.ProVersion ?? "false"
theStatus = theStatusText == "true" ? true : false

} catch {
print("Getting the ProVersion Status failed! \(VC_String) \(error)")
}
return theStatus
}

// Set ProVersion to true.
static func setProVersionToPurchased()
{
let VC_String = "IAPHandler"

do {
try Database.shared.databaseConnection!.write { db in
try db.execute(sql: "UPDATE My_Settings SET ProVersion = :proVersion WHERE Settings_ID = :id",
arguments: ["proVersion": "true", "id": 1])
}
} catch {
print("Update set pro version, failed! \(VC_String)s \(error)")
}
}

}// End of class


Подробнее здесь: https://stackoverflow.com/questions/793 ... storekit-2
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»