This commit is contained in:
Pavel Tikhonenko
2021-11-01 20:11:08 +03:00
parent 14f707e28f
commit b94b280f60
3 changed files with 28 additions and 5 deletions
+26 -3
View File
@@ -138,7 +138,10 @@ public extension InAppReceipt
@available(watchOSApplicationExtension 6.2, *)
static func refresh(completion: @escaping IAPRefreshRequestResult)
{
if refreshSession != nil { return }
if refreshSession != nil
{
return
}
refreshSession = RefreshSession()
refreshSession!.refresh { (error) in
@@ -147,12 +150,28 @@ public extension InAppReceipt
}
}
/// Cancel refreshing local in-app receipt
@available(watchOSApplicationExtension 6.2, *)
static func cancelRefreshSession()
{
refreshSession?.cancel()
}
@available(watchOSApplicationExtension 6.2, *)
static fileprivate func destroyRefreshSession()
{
refreshSession = nil
}
/// Check whether receipt is refreshing now
///
/// - Returns `true` if receipt is refreshing now, otherwise `false`
@available(watchOSApplicationExtension 6.2, *)
static var isReceiptRefreshingNow: Bool
{
refreshSession != nil
}
/// Check whether user is eligible for introductory offer for any products within the same subscription group
///
/// - Returns `false` if user isn't eligible for introductory offer, otherwise `true`
@@ -174,7 +193,6 @@ fileprivate class RefreshSession : NSObject, SKRequestDelegate
private let receiptRefreshRequest = SKReceiptRefreshRequest()
private var completion: IAPRefreshRequestResult?
override init()
{
super.init()
@@ -205,10 +223,15 @@ fileprivate class RefreshSession : NSObject, SKRequestDelegate
func requestDidFinish(with error: Error?)
{
DispatchQueue.main.async { [weak self] in
self?.completion?(error)
self?.completion?(error)
}
receiptRefreshRequest.cancel()
}
func cancel()
{
receiptRefreshRequest.cancel()
}
}
#endif
+1 -1
View File
@@ -18,7 +18,7 @@ public enum IARError: Error
case initializationFailed(reason: ReceiptInitializationFailureReason)
case validationFailed(reason: ValidationFailureReason)
case purchaseExpired
case receiptRefreshingInProgress
/// The underlying reason the receipt initialization error occurred.
///
/// - appStoreReceiptNotFound: In-App Receipt not found
+1 -1
View File
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "TPInAppReceipt"
s.version = "3.3.0"
s.version = "3.3.1"
s.summary = "Reading and Validating In App Purchase Receipt Locally"
s.description = "A lightweight iOS/OSX library for reading and validating Apple In App Purchase Receipt locally. Pure swift, No OpenSSL!"