Commit 2cb05fe1 by Sarkizz

添加图片加载超时逻辑

parent bb9f04c8
......@@ -26,6 +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 assest: PHAsset!
public var isSelected = false
......@@ -35,6 +36,9 @@ open class MRAlbumDetailViewController: UIViewController {
private let imageView = UIImageView()
private let checkButton = UIButton(type: .custom)
private var requestID: PHImageRequestID?
private var countdownor: Countdown?
private var state: AlbumDetailState = .none {
didSet {
stateDidChange()
......@@ -110,12 +114,18 @@ extension MRAlbumDetailViewController {
let options = PHImageRequestOptions()
options.isNetworkAccessAllowed = true
options.isSynchronous = true
self.imageCache.requestImage(for: self.assest, targetSize: PHImageManagerMaximumSize, contentMode: .default, options: options, resultHandler: { (image, _) in
self.requestID = self.imageCache.requestImage(for: self.assest, targetSize: PHImageManagerMaximumSize, contentMode: .default, options: options, resultHandler: { (image, _) in
DispatchQueue.main.async {
ToastView.hide()
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)
}
})
}
}
......
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