Merge pull request #288 from James-Sangalli/fix-iphone-x-background-crash

Fix: crash on iPhone X while fetching transactions in background.
pull/299/head
James Sangalli 7 years ago committed by GitHub
commit c25049aa8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      Trust/Transactions/Coordinators/TransactionDataCoordinator.swift

@ -45,20 +45,39 @@ class TransactionDataCoordinator {
) {
self.session = session
self.storage = storage
NotificationCenter.default.addObserver(self, selector: #selector(stopTimers), name: .UIApplicationWillResignActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(restartTimers), name: .UIApplicationDidBecomeActive, object: nil)
}
func start() {
runScheduledTimers()
// Start fetching all transactions process.
if transactionsTracker.fetchingState != .done {
initialFetch(for: session.account.address, page: 0) { _ in }
}
}
@objc func stopTimers() {
timer?.invalidate()
timer = nil
updateTransactionsTimer?.invalidate()
updateTransactionsTimer = nil
}
@objc func restartTimers() {
runScheduledTimers()
}
private func runScheduledTimers() {
guard timer == nil, updateTransactionsTimer == nil else {
return
}
timer = Timer.scheduledTimer(timeInterval: 5, target: BlockOperation { [weak self] in
self?.fetchPending()
}, selector: #selector(Operation.main), userInfo: nil, repeats: true)
updateTransactionsTimer = Timer.scheduledTimer(timeInterval: 15, target: BlockOperation { [weak self] in
self?.fetchTransactions()
}, selector: #selector(Operation.main), userInfo: nil, repeats: true)
// Start fetching all transactions process.
if transactionsTracker.fetchingState != .done {
initialFetch(for: session.account.address, page: 0) { _ in }
}
}
func fetch() {

Loading…
Cancel
Save