mirror of
https://github.com/bizz84/SwiftyStoreKit.git
synced 2025-11-25 03:15:09 +08:00
Merge pull request #584 from muukii/muukii/handle-completed-request
[Fix issue] Call completion closure on completed request
This commit is contained in:
@@ -31,13 +31,20 @@ public protocol InAppRequest: class {
|
||||
func cancel()
|
||||
}
|
||||
|
||||
protocol InAppProductRequest: InAppRequest { }
|
||||
protocol InAppProductRequest: InAppRequest {
|
||||
var hasCompleted: Bool { get }
|
||||
var cachedResults: RetrieveResults? { get }
|
||||
}
|
||||
|
||||
class InAppProductQueryRequest: NSObject, InAppProductRequest, SKProductsRequestDelegate {
|
||||
|
||||
private let callback: InAppProductRequestCallback
|
||||
private let request: SKProductsRequest
|
||||
|
||||
private(set) var cachedResults: RetrieveResults?
|
||||
|
||||
var hasCompleted: Bool { cachedResults != nil }
|
||||
|
||||
deinit {
|
||||
request.delegate = nil
|
||||
}
|
||||
@@ -52,6 +59,7 @@ class InAppProductQueryRequest: NSObject, InAppProductRequest, SKProductsRequest
|
||||
func start() {
|
||||
request.start()
|
||||
}
|
||||
|
||||
func cancel() {
|
||||
request.cancel()
|
||||
}
|
||||
@@ -61,8 +69,12 @@ class InAppProductQueryRequest: NSObject, InAppProductRequest, SKProductsRequest
|
||||
|
||||
let retrievedProducts = Set<SKProduct>(response.products)
|
||||
let invalidProductIDs = Set<String>(response.invalidProductIdentifiers)
|
||||
performCallback(RetrieveResults(retrievedProducts: retrievedProducts,
|
||||
invalidProductIDs: invalidProductIDs, error: nil))
|
||||
let results = RetrieveResults(
|
||||
retrievedProducts: retrievedProducts,
|
||||
invalidProductIDs: invalidProductIDs, error: nil
|
||||
)
|
||||
self.cachedResults = results
|
||||
performCallback(results)
|
||||
}
|
||||
|
||||
func requestDidFinish(_ request: SKRequest) {
|
||||
|
||||
@@ -81,9 +81,21 @@ class ProductsInfoController: NSObject {
|
||||
}
|
||||
inflightRequests[productIds] = InAppProductQuery(request: request, completionHandlers: [completion])
|
||||
request.start()
|
||||
|
||||
return request
|
||||
|
||||
} else {
|
||||
|
||||
inflightRequests[productIds]!.completionHandlers.append(completion)
|
||||
|
||||
let query = inflightRequests[productIds]!
|
||||
|
||||
if query.request.hasCompleted {
|
||||
query.completionHandlers.forEach {
|
||||
$0(query.request.cachedResults!)
|
||||
}
|
||||
}
|
||||
|
||||
return inflightRequests[productIds]!.request
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ Pod::Spec.new do |s|
|
||||
s.license = 'MIT'
|
||||
s.homepage = 'https://github.com/bizz84/SwiftyStoreKit'
|
||||
s.author = { 'Andrea Bizzotto' => 'bizz84@gmail.com' }
|
||||
s.ios.deployment_target = '8.0'
|
||||
s.ios.deployment_target = '9.0'
|
||||
s.osx.deployment_target = '10.10'
|
||||
s.tvos.deployment_target = '9.0'
|
||||
s.watchos.deployment_target = '6.2'
|
||||
|
||||
@@ -195,7 +195,7 @@
|
||||
/* Begin PBXFileReference section */
|
||||
2F2B8B2124A64CC000CEF088 /* SKProductDiscount+LocalizedPrice.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "SKProductDiscount+LocalizedPrice.swift"; path = "Sources/SwiftyStoreKit/SKProductDiscount+LocalizedPrice.swift"; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2224A64CC000CEF088 /* AppleReceiptValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppleReceiptValidator.swift; path = Sources/SwiftyStoreKit/AppleReceiptValidator.swift; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2324A64CC000CEF088 /* InAppProductQueryRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InAppProductQueryRequest.swift; path = Sources/SwiftyStoreKit/InAppProductQueryRequest.swift; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2324A64CC000CEF088 /* InAppProductQueryRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; name = InAppProductQueryRequest.swift; path = Sources/SwiftyStoreKit/InAppProductQueryRequest.swift; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2424A64CC000CEF088 /* InAppReceipt.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InAppReceipt.swift; path = Sources/SwiftyStoreKit/InAppReceipt.swift; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2524A64CC000CEF088 /* SwiftyStoreKit+Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "SwiftyStoreKit+Types.swift"; path = "Sources/SwiftyStoreKit/SwiftyStoreKit+Types.swift"; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2624A64CC000CEF088 /* CompleteTransactionsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CompleteTransactionsController.swift; path = Sources/SwiftyStoreKit/CompleteTransactionsController.swift; sourceTree = SOURCE_ROOT; };
|
||||
@@ -203,7 +203,7 @@
|
||||
2F2B8B2824A64CC000CEF088 /* InAppReceiptRefreshRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InAppReceiptRefreshRequest.swift; path = Sources/SwiftyStoreKit/InAppReceiptRefreshRequest.swift; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2924A64CC100CEF088 /* InAppReceiptVerificator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InAppReceiptVerificator.swift; path = Sources/SwiftyStoreKit/InAppReceiptVerificator.swift; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2A24A64CC100CEF088 /* SKProduct+LocalizedPrice.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "SKProduct+LocalizedPrice.swift"; path = "Sources/SwiftyStoreKit/SKProduct+LocalizedPrice.swift"; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2B24A64CC100CEF088 /* ProductsInfoController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProductsInfoController.swift; path = Sources/SwiftyStoreKit/ProductsInfoController.swift; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2B24A64CC100CEF088 /* ProductsInfoController.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; name = ProductsInfoController.swift; path = Sources/SwiftyStoreKit/ProductsInfoController.swift; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2C24A64CC100CEF088 /* OS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OS.swift; path = Sources/SwiftyStoreKit/OS.swift; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2D24A64CC100CEF088 /* PaymentsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PaymentsController.swift; path = Sources/SwiftyStoreKit/PaymentsController.swift; sourceTree = SOURCE_ROOT; };
|
||||
2F2B8B2E24A64CC100CEF088 /* SwiftyStoreKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftyStoreKit.swift; path = Sources/SwiftyStoreKit/SwiftyStoreKit.swift; sourceTree = SOURCE_ROOT; };
|
||||
|
||||
Reference in New Issue
Block a user