Commit 6935e944 by Sarkizz

修正逻辑

parent cc52af77
......@@ -169,29 +169,31 @@ extension MRAlbumListViewController {
var count = assests.count
var images = [UIImage]()
var requestIDs = [PHImageRequestID]()
var block = false
let finish: (_ image: UIImage?, _ info: [AnyHashable: Any]?) -> Void = { image, info in
//移除已完成的id
if let idNum = info?[PHImageResultRequestIDKey] as? NSNumber {
requestIDs.removeAll(where: { $0 == idNum.int32Value })
}
//每个图片请求完成的操作
if let image = image {
images.append(image)
count -= 1
} else {
//若其中一个请求失败,直接中断所有请求任务
let error = info?[PHImageErrorKey] as? String ?? "获取图片失败"
completion(nil, error)
count = assests.count
requestIDs.forEach({ self.imageCache.cancelImageRequest($0) })
}
DispatchQueue.main.async {
progress?(Float((assests.count - count)/assests.count))
if !block {
//移除已完成的id
if let idNum = info?[PHImageResultRequestIDKey] as? NSNumber {
requestIDs.removeAll(where: { $0 == idNum.int32Value })
}
//每个图片请求完成的操作
if let image = image {
images.append(image)
count -= 1
} else {
//若其中一个请求失败,直接中断所有请求任务
let error = info?[PHImageErrorKey] as? String ?? "获取图片失败"
block = true
completion(nil, error)
requestIDs.forEach({ self.imageCache.cancelImageRequest($0) })
}
if count <= 0 {
completion(images, nil)
DispatchQueue.main.async {
progress?(Float((assests.count - count)/assests.count))
if count <= 0 {
completion(images, nil)
}
}
}
}
......
......@@ -19,11 +19,10 @@ public class SAMutableSelectionAlbum: MRAlbumListViewController {
public override func confirm() {
ToastView.loading()
requestImages(with: selectedAssests) { (images, error) in
requestImages(with: selectedAssests, size: maxImageSize) { (images, error) in
ToastView.hide(animate: false)
if let images = images {
self.didFinish?(self, images)
} else {
let error = error ?? "获取图片失败"
ToastView.show(error)
......
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