From 3d87a678b530bf47f1deea8a554c067f69c93117 Mon Sep 17 00:00:00 2001 From: Samuel Spencer Date: Mon, 21 Sep 2020 16:51:17 -0500 Subject: [PATCH 1/3] Update Package.swift Bumped minimum iOS deployment version from 8 to 9 in order to comply with Xcode 12's minimum deployment range. Fixes compiler warning when installing via SPM. --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 83d5bbb..f180bb4 100644 --- a/Package.swift +++ b/Package.swift @@ -3,7 +3,7 @@ import PackageDescription let package = Package( name: "SwiftyStoreKit", - platforms: [.iOS("8.0"), .macOS("10.10"), .tvOS("9.0"), .watchOS("6.2")], + platforms: [.iOS("9.0"), .macOS("10.10"), .tvOS("9.0"), .watchOS("6.2")], products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( From 6b782ae59be0453a0c720b941b7a33d63a319d88 Mon Sep 17 00:00:00 2001 From: Samuel Spencer Date: Mon, 21 Sep 2020 16:53:36 -0500 Subject: [PATCH 2/3] Update SwiftyStoreKit.podspec Bumped minimum iOS deployment version from 8 to 9 in order to comply with Xcode 12's minimum deployment range. Fixes compiler warning when installing via CocoaPods. Fixes #578. --- SwiftyStoreKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyStoreKit.podspec b/SwiftyStoreKit.podspec index 4fac70f..a316174 100644 --- a/SwiftyStoreKit.podspec +++ b/SwiftyStoreKit.podspec @@ -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' From 24a58abb763c8041ecbc6326cad9396bf24aa925 Mon Sep 17 00:00:00 2001 From: Muukii Date: Tue, 29 Sep 2020 06:10:42 +0900 Subject: [PATCH 3/3] Call completion closure on completed request --- .../InAppProductQueryRequest.swift | 18 +++++++++++++++--- .../ProductsInfoController.swift | 12 ++++++++++++ SwiftyStoreKit.xcodeproj/project.pbxproj | 4 ++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Sources/SwiftyStoreKit/InAppProductQueryRequest.swift b/Sources/SwiftyStoreKit/InAppProductQueryRequest.swift index 97c9f88..3494f27 100644 --- a/Sources/SwiftyStoreKit/InAppProductQueryRequest.swift +++ b/Sources/SwiftyStoreKit/InAppProductQueryRequest.swift @@ -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(response.products) let invalidProductIDs = Set(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) { diff --git a/Sources/SwiftyStoreKit/ProductsInfoController.swift b/Sources/SwiftyStoreKit/ProductsInfoController.swift index 591e26a..0478439 100644 --- a/Sources/SwiftyStoreKit/ProductsInfoController.swift +++ b/Sources/SwiftyStoreKit/ProductsInfoController.swift @@ -69,9 +69,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 } } diff --git a/SwiftyStoreKit.xcodeproj/project.pbxproj b/SwiftyStoreKit.xcodeproj/project.pbxproj index 90d958d..63e44ea 100644 --- a/SwiftyStoreKit.xcodeproj/project.pbxproj +++ b/SwiftyStoreKit.xcodeproj/project.pbxproj @@ -200,7 +200,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; }; @@ -208,7 +208,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; };