Skip to content

Commit

Permalink
IMAPlugin Unowned Self Crash Fix (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoBendixson authored and x-NR-x committed Mar 25, 2019
1 parent f91ace5 commit 6528c63
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions IMAPlugin.swift
Expand Up @@ -192,20 +192,23 @@ enum IMAState: Int, StateProtocol {
// notify ads requested
self.notify(event: AdEvent.AdsRequested(adTagUrl: self.config.adTagUrl))
// start timeout timer
self.requestTimeoutTimer = PKTimer.after(self.requestTimeoutInterval) { [unowned self] _ in
if self.adsManager == nil {
self.requestTimeoutTimer = PKTimer.after(self.requestTimeoutInterval) { [weak self] _ in

guard let strongSelf = self else { return }

if strongSelf.adsManager == nil {
PKLog.debug("Ads request timed out")
switch self.stateMachine.getState() {
case .adsRequested: self.delegate?.adsRequestTimedOut(shouldPlay: false)
case .adsRequestedAndPlay: self.delegate?.adsRequestTimedOut(shouldPlay: true)
switch strongSelf.stateMachine.getState() {
case .adsRequested: strongSelf.delegate?.adsRequestTimedOut(shouldPlay: false)
case .adsRequestedAndPlay: strongSelf.delegate?.adsRequestTimedOut(shouldPlay: true)
default: break // should not receive timeout for any other state
}
// set state to request failure
self.stateMachine.set(state: .adsRequestTimedOut)
strongSelf.stateMachine.set(state: .adsRequestTimedOut)

self.invalidateRequestTimer()
strongSelf.invalidateRequestTimer()
// post ads request timeout event
self.notify(event: AdEvent.RequestTimedOut())
strongSelf.notify(event: AdEvent.RequestTimedOut())
}
}
}
Expand Down

0 comments on commit 6528c63

Please sign in to comment.