Commit 9b9cff45 by Sarkizz

修正超时逻辑问题

parent e39a6907
......@@ -26,7 +26,7 @@ open class MRAlbumDetailViewController: UIViewController {
public static var checkedOptions: MRCheckBoxOptions = .defaultCheck(checkboxSize)
public var confirm: ((_ vc: MRAlbumDetailViewController, _ isSelected: Bool) -> Void)?
public var requestTimeout: TimeInterval = 20
public var requestTimeout = 20
public var assest: PHAsset!
public var isSelected = false
......@@ -117,15 +117,21 @@ extension MRAlbumDetailViewController {
self.requestID = self.imageCache.requestImage(for: self.assest, targetSize: PHImageManagerMaximumSize, contentMode: .default, options: options, resultHandler: { (image, _) in
DispatchQueue.main.async {
ToastView.hide()
self.requestID = nil
completion(image, nil)
}
})
weak var weakSelf = self
self.countdownor = self.requestTimeout.countdown({ (_, _, _, sec) in
if sec <= 0, let `self` = weakSelf, let id = self.requestID {
self.imageCache.cancelImageRequest(id)
}
})
}
startTimeoutCheck()
}
private func startTimeoutCheck() {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.seconds(self.requestTimeout)) {
if let id = self.requestID {
self.imageCache.cancelImageRequest(id)
self.requestID = nil
ToastView.hide()
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment