diff --git a/KinEcosystem.podspec b/KinEcosystem.podspec index 6b5bedc..4b82eec 100644 --- a/KinEcosystem.podspec +++ b/KinEcosystem.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'KinEcosystem' - s.version = '0.9.0' + s.version = '0.9.1' s.summary = 'Kin Ecosystem mobile sdk for iOS' s.description = <<-DESC Kin ecosystem mobile sdk for iOS @@ -11,7 +11,7 @@ Kin ecosystem mobile sdk for iOS s.author = { 'Kin' => 'kin@kinfoundation.com' } s.source = { :git => 'https://github.com/kinfoundation/kin-ecosystem-ios-sdk.git', :tag => s.version.to_s } - s.ios.deployment_target = '8.1' + s.ios.deployment_target = '9.0' s.resource_bundle = { "kinLocalization" => ["KinEcosystem/*.lproj/*.strings"] } s.source_files = 'KinEcosystem/**/*.{h,m,swift}' s.resources = 'KinEcosystem/**/*.{xcassets,xcdatamodeld,storyboard,xib,png,pdf,jpg,json,strings}' diff --git a/KinEcosystem/Core/Kin.swift b/KinEcosystem/Core/Kin.swift index 740a61a..6d329cc 100644 --- a/KinEcosystem/Core/Kin.swift +++ b/KinEcosystem/Core/Kin.swift @@ -13,7 +13,7 @@ import StellarErrors import KinUtil import KinMigrationModule -let SDKVersion = "0.9.0" +let SDKVersion = "0.9.1" public typealias KinUserStatsCallback = (UserStats?, Error?) -> () public typealias KinLoginCallback = (Error?) -> () @@ -72,6 +72,9 @@ public class Kin { fileprivate var nativeOffersInc:Int32 = -1 fileprivate var brManager:BRManager? + // a temporary workaround to StellarKit.TransactionError.txBAD_SEQ + fileprivate let purchaseQueue = OperationQueue() + public var lastKnownBalance: Balance? { return core?.blockchain.lastBalance ?? nil } @@ -95,6 +98,16 @@ public class Kin { } } + init() { + purchaseQueue.maxConcurrentOperationCount = 1 + NotificationCenter.default.addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { _ in + self.purchaseQueue.isSuspended = true + } + NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: nil) { _ in + self.purchaseQueue.isSuspended = false + } + } + public func start(environment: Environment) throws { guard core == nil else { return @@ -377,19 +390,31 @@ public class Kin { return false } defer { - _ = attemptEx(2, closure: { attemptNum -> Promise in - return core.onboard() - .then { - Flows.nativeSpend(jwt: offerJWT, core: core) + // a temporary workaround to StellarKit.TransactionError.txBAD_SEQ + purchaseQueue.addOperation { + let group = DispatchGroup() + group.enter() + let attempt = attemptEx(2, closure: { attemptNum -> Promise in + return core.onboard() + .then { + Flows.nativeSpend(jwt: offerJWT, core: core) + } + }) { error in + self.recoverByMigratingIfNeeded(from: error) + }.then { jwt in + completion(jwt, nil) + }.error { error in + completion(nil, KinEcosystemError.transform(error)) } - }) { error in - self.recoverByMigratingIfNeeded(from: error) - }.then { jwt in - completion(jwt, nil) - }.error { error in - completion(nil, KinEcosystemError.transform(error)) + + attempt.finally { + group.leave() + } + + group.wait() } + } return true }