mirror of
https://github.com/bizz84/SwiftyStoreKit.git
synced 2025-11-26 03:28:39 +08:00
Merge pull request #572 from motocodeltd/add_support_for_entitlement_revocation
add support for ios14 entitlement revocation
This commit is contained in:
@@ -88,6 +88,14 @@ extension SKPaymentTransactionState: CustomDebugStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
struct EntitlementRevocation {
|
||||
let callback: ([String]) -> Void
|
||||
|
||||
init(callback: @escaping ([String]) -> Void) {
|
||||
self.callback = callback
|
||||
}
|
||||
}
|
||||
|
||||
class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
||||
|
||||
private let paymentsController: PaymentsController
|
||||
@@ -98,6 +106,8 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
||||
|
||||
unowned let paymentQueue: PaymentQueue
|
||||
|
||||
private var entitlementRevocation: EntitlementRevocation?
|
||||
|
||||
deinit {
|
||||
paymentQueue.remove(self)
|
||||
}
|
||||
@@ -145,6 +155,15 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
||||
paymentsController.append(payment)
|
||||
}
|
||||
|
||||
func onEntitlementRevocation(_ revocation: EntitlementRevocation) {
|
||||
guard entitlementRevocation == nil else {
|
||||
print("SwiftyStoreKit.onEntitlementRevocation() should only be called once when the app launches. Ignoring this call")
|
||||
return
|
||||
}
|
||||
|
||||
self.entitlementRevocation = revocation
|
||||
}
|
||||
|
||||
func restorePurchases(_ restorePurchases: RestorePurchases) {
|
||||
assertCompleteTransactionsWasCalled()
|
||||
|
||||
@@ -233,6 +252,11 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
|
||||
}
|
||||
}
|
||||
|
||||
func paymentQueue(_ queue: SKPaymentQueue, didRevokeEntitlementsForProductIdentifiers productIdentifiers: [String]) {
|
||||
|
||||
self.entitlementRevocation?.callback(productIdentifiers)
|
||||
}
|
||||
|
||||
func paymentQueue(_ queue: SKPaymentQueue, removedTransactions transactions: [SKPaymentTransaction]) {
|
||||
|
||||
}
|
||||
|
||||
@@ -85,6 +85,11 @@ public class SwiftyStoreKit {
|
||||
paymentQueueController.completeTransactions(CompleteTransactions(atomically: atomically, callback: completion))
|
||||
}
|
||||
|
||||
fileprivate func onEntitlementRevocation(completion: @escaping ([String]) -> Void) {
|
||||
|
||||
paymentQueueController.onEntitlementRevocation(EntitlementRevocation(callback: completion))
|
||||
}
|
||||
|
||||
fileprivate func finishTransaction(_ transaction: PaymentTransaction) {
|
||||
|
||||
paymentQueueController.finishTransaction(transaction)
|
||||
@@ -188,6 +193,14 @@ extension SwiftyStoreKit {
|
||||
sharedInstance.completeTransactions(atomically: atomically, completion: completion)
|
||||
}
|
||||
|
||||
/// Entitlement revocation notification
|
||||
/// - Parameter completion: handler for result (list of product identifiers revoked)
|
||||
@available(iOS 14, tvOS 14, OSX 11, watchOS 7, macCatalyst 14, *)
|
||||
public class func onEntitlementRevocation(completion: @escaping ([String]) -> Void) {
|
||||
|
||||
sharedInstance.onEntitlementRevocation(completion: completion)
|
||||
}
|
||||
|
||||
/// Finish a transaction
|
||||
///
|
||||
/// Once the content has been delivered, call this method to finish a transaction that was performed non-atomically
|
||||
|
||||
Reference in New Issue
Block a user