Handle errors in product requests

Update Convenience due to main queue bugs.
This commit is contained in:
Davide De Rosa 2019-11-30 11:42:21 +01:00
parent d302e504df
commit c1c7587c8c
6 changed files with 35 additions and 22 deletions

View File

@ -66,12 +66,14 @@ class ProductManager: NSObject {
SKPaymentQueue.default().remove(self) SKPaymentQueue.default().remove(self)
} }
func listProducts(completionHandler: (([SKProduct]) -> Void)?) { func listProducts(completionHandler: (([SKProduct]?, Error?) -> Void)?) {
inApp.requestProducts(withIdentifiers: Product.all) { _ in inApp.requestProducts(withIdentifiers: Product.all, completionHandler: { _ in
log.debug("In-app products: \(self.inApp.products.map { $0.productIdentifier })") log.debug("In-app products: \(self.inApp.products.map { $0.productIdentifier })")
completionHandler?(self.inApp.products) completionHandler?(self.inApp.products, nil)
} }, failureHandler: {
completionHandler?(nil, $0)
})
} }
func product(withIdentifier identifier: Product) -> SKProduct? { func product(withIdentifier identifier: Product) -> SKProduct? {

View File

@ -27,6 +27,9 @@ import UIKit
import StoreKit import StoreKit
import PassepartoutCore import PassepartoutCore
import Convenience import Convenience
import SwiftyBeaver
private let log = SwiftyBeaver.self
class DonationViewController: UITableViewController, StrongTableHost { class DonationViewController: UITableViewController, StrongTableHost {
private var donationList: [Product] = [] private var donationList: [Product] = []
@ -81,7 +84,11 @@ class DonationViewController: UITableViewController, StrongTableHost {
ProductManager.shared.listProducts { ProductManager.shared.listProducts {
self.isLoading = false self.isLoading = false
self.setProducts($0) guard let products = $0 else {
log.error("Unable to list products: \($1?.localizedDescription ?? "")")
return
}
self.setProducts(products)
} }
} }

View File

@ -94,10 +94,14 @@ class WizardProviderViewController: UITableViewController, StrongTableHost {
return return
} }
ProductManager.shared.listProducts { _ in ProductManager.shared.listProducts { (products, error) in
hud.hide()
if let error = error {
log.error("Unable to list products: \(error)")
return
}
self?.reloadModel() self?.reloadModel()
self?.tableView.reloadData() self?.tableView.reloadData()
hud.hide()
} }
} }
} }

View File

@ -90,7 +90,7 @@ class PurchaseViewController: UITableViewController, StrongTableHost {
super.viewDidAppear(animated) super.viewDidAppear(animated)
let hud = HUD(view: view) let hud = HUD(view: view)
ProductManager.shared.listProducts { [weak self] _ in ProductManager.shared.listProducts { [weak self] (_, _) in
self?.reloadModel() self?.reloadModel()
self?.isLoading = false self?.isLoading = false
self?.tableView.reloadData() self?.tableView.reloadData()

View File

@ -14,7 +14,7 @@ def shared_pods
pod 'SSZipArchive' pod 'SSZipArchive'
for spec in ['About', 'Alerts', 'Dialogs', 'InApp', 'Misc', 'Options', 'Persistence', 'Reviewer', 'Tables', 'WebServices'] do for spec in ['About', 'Alerts', 'Dialogs', 'InApp', 'Misc', 'Options', 'Persistence', 'Reviewer', 'Tables', 'WebServices'] do
pod "Convenience/#{spec}", :git => 'https://github.com/keeshux/convenience', :commit => '7fe7dcf' pod "Convenience/#{spec}", :git => 'https://github.com/keeshux/convenience', :commit => '3a191e8'
#pod "Convenience/#{spec}", :path => '../../personal/convenience' #pod "Convenience/#{spec}", :path => '../../personal/convenience'
end end
end end

View File

@ -36,16 +36,16 @@ PODS:
- TunnelKit/Core - TunnelKit/Core
DEPENDENCIES: DEPENDENCIES:
- Convenience/About (from `https://github.com/keeshux/convenience`, commit `7fe7dcf`) - Convenience/About (from `https://github.com/keeshux/convenience`, commit `3a191e8`)
- Convenience/Alerts (from `https://github.com/keeshux/convenience`, commit `7fe7dcf`) - Convenience/Alerts (from `https://github.com/keeshux/convenience`, commit `3a191e8`)
- Convenience/Dialogs (from `https://github.com/keeshux/convenience`, commit `7fe7dcf`) - Convenience/Dialogs (from `https://github.com/keeshux/convenience`, commit `3a191e8`)
- Convenience/InApp (from `https://github.com/keeshux/convenience`, commit `7fe7dcf`) - Convenience/InApp (from `https://github.com/keeshux/convenience`, commit `3a191e8`)
- Convenience/Misc (from `https://github.com/keeshux/convenience`, commit `7fe7dcf`) - Convenience/Misc (from `https://github.com/keeshux/convenience`, commit `3a191e8`)
- Convenience/Options (from `https://github.com/keeshux/convenience`, commit `7fe7dcf`) - Convenience/Options (from `https://github.com/keeshux/convenience`, commit `3a191e8`)
- Convenience/Persistence (from `https://github.com/keeshux/convenience`, commit `7fe7dcf`) - Convenience/Persistence (from `https://github.com/keeshux/convenience`, commit `3a191e8`)
- Convenience/Reviewer (from `https://github.com/keeshux/convenience`, commit `7fe7dcf`) - Convenience/Reviewer (from `https://github.com/keeshux/convenience`, commit `3a191e8`)
- Convenience/Tables (from `https://github.com/keeshux/convenience`, commit `7fe7dcf`) - Convenience/Tables (from `https://github.com/keeshux/convenience`, commit `3a191e8`)
- Convenience/WebServices (from `https://github.com/keeshux/convenience`, commit `7fe7dcf`) - Convenience/WebServices (from `https://github.com/keeshux/convenience`, commit `3a191e8`)
- Kvitto - Kvitto
- MBProgressHUD - MBProgressHUD
- SSZipArchive - SSZipArchive
@ -63,7 +63,7 @@ SPEC REPOS:
EXTERNAL SOURCES: EXTERNAL SOURCES:
Convenience: Convenience:
:commit: 7fe7dcf :commit: 3a191e8
:git: https://github.com/keeshux/convenience :git: https://github.com/keeshux/convenience
TunnelKit: TunnelKit:
:commit: 8b17a13 :commit: 8b17a13
@ -71,7 +71,7 @@ EXTERNAL SOURCES:
CHECKOUT OPTIONS: CHECKOUT OPTIONS:
Convenience: Convenience:
:commit: 7fe7dcf :commit: 3a191e8
:git: https://github.com/keeshux/convenience :git: https://github.com/keeshux/convenience
TunnelKit: TunnelKit:
:commit: 8b17a13 :commit: 8b17a13
@ -87,6 +87,6 @@ SPEC CHECKSUMS:
SwiftyBeaver: 3d3e93a12d648bd400b6f2948a7ef128b5b183c7 SwiftyBeaver: 3d3e93a12d648bd400b6f2948a7ef128b5b183c7
TunnelKit: 4b70c0d8b6727b407248b4271b7613225f63204b TunnelKit: 4b70c0d8b6727b407248b4271b7613225f63204b
PODFILE CHECKSUM: 10c7cb879b6ee3d5185f541e6a2c6d14e988ff0b PODFILE CHECKSUM: 5b0c1f2c23e4a3ffa33152e231291a97351d7165
COCOAPODS: 1.8.4 COCOAPODS: 1.8.4