diff --git a/Sources/Extras.swift b/Sources/Extras.swift index 0e9f97b..51c8e65 100644 --- a/Sources/Extras.swift +++ b/Sources/Extras.swift @@ -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 diff --git a/Sources/IARError.swift b/Sources/IARError.swift index e139bf3..5722869 100644 --- a/Sources/IARError.swift +++ b/Sources/IARError.swift @@ -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 diff --git a/TPInAppReceipt.podspec b/TPInAppReceipt.podspec index 988ad99..1ef6c92 100644 --- a/TPInAppReceipt.podspec +++ b/TPInAppReceipt.podspec @@ -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!"