Commit 48ab844b authored by shenyong's avatar shenyong

Merge branch 'Advertisement' of gitlab.huolea.com:ShuMing/phonemanager into Advertisement

parents 3f0745ed 0d4d241e
...@@ -41,14 +41,14 @@ class CompressSelectCell : UICollectionViewCell { ...@@ -41,14 +41,14 @@ class CompressSelectCell : UICollectionViewCell {
let compressCompletedSize = Double(compressedData.count) let compressCompletedSize = Double(compressedData.count)
let saveSize = model.orgSize - compressCompletedSize let saveSize = model.orgSize - compressCompletedSize
let sizeKB : Double = saveSize/1024 let sizeKB : Double = saveSize/1000
DispatchQueue.main.async { DispatchQueue.main.async {
if sizeKB < 1024{ if sizeKB < 1000{
self.saveSizeLabel.text = String(format: "Save %.2f KB" ,sizeKB) self.saveSizeLabel.text = String(format: "Save %.2f KB" ,sizeKB)
}else if sizeKB < (1024 * 1024) && sizeKB > 1024{ }else if sizeKB < (1000 * 1000) && sizeKB > 1000{
self.saveSizeLabel.text = String(format: "Save %.2f MB" ,sizeKB/1024) self.saveSizeLabel.text = String(format: "Save %.2f MB" ,sizeKB/1000)
}else{ }else{
self.saveSizeLabel.text = String(format: "Save %.2f GB" ,sizeKB/(1024 * 1024)) self.saveSizeLabel.text = String(format: "Save %.2f GB" ,sizeKB/(1000 * 1000))
} }
} }
} }
......
...@@ -199,15 +199,15 @@ class CompressQualityController : BaseViewController{ ...@@ -199,15 +199,15 @@ class CompressQualityController : BaseViewController{
orgAllSize = orgAllSize + modelData.orgSize orgAllSize = orgAllSize + modelData.orgSize
} }
sum = orgAllSize - compressAllSize sum = orgAllSize - compressAllSize
sum = sum / 1024 sum = sum / 1000
if sum < 1024{ if sum < 1000{
vc.sizeToplabel.text = String(format:"%.2lfKB",sum) vc.sizeToplabel.text = String(format:"%.2lfKB",sum)
}else if sum < (1024 * 1024) && sum > 1024{ }else if sum < (1000 * 1000) && sum > 1000{
sum = sum / 1024 sum = sum / 1000
vc.sizeToplabel.text = String(format:"%.2lfMB",sum) vc.sizeToplabel.text = String(format:"%.2lfMB",sum)
}else{ }else{
sum = sum / (1024 * 1024) sum = sum / (1000 * 1000)
vc.sizeToplabel.text = String(format:"%.2lfGB",sum) vc.sizeToplabel.text = String(format:"%.2lfGB",sum)
} }
let str = String(format:"%.2lf",(orgAllSize - compressAllSize) / orgAllSize) let str = String(format:"%.2lf",(orgAllSize - compressAllSize) / orgAllSize)
......
...@@ -22,21 +22,21 @@ class CompressCustomHeaderView: UICollectionReusableView{ ...@@ -22,21 +22,21 @@ class CompressCustomHeaderView: UICollectionReusableView{
saveSum = saveSum + model.orgSize * 0.8 saveSum = saveSum + model.orgSize * 0.8
} }
sum = sum / 1000 sum = sum / 1000
saveSum = saveSum / 1024 saveSum = saveSum / 1000
if sum < 1024 { if sum < 1000 {
self.siezLabel.text = String(format: "%.2f KB" ,(sum)) self.siezLabel.text = String(format: "%.2f KB" ,(sum))
}else if sum < (1024 * 1024) && sum > 1024{ }else if sum < (1000 * 1000) && sum > 1024{
self.siezLabel.text = String(format: "%.2f MB" ,(sum/1024)) self.siezLabel.text = String(format: "%.2f MB" ,(sum/1000))
}else{ }else{
self.siezLabel.text = String(format: "%.2f GB" ,sum/(1024*1024)) self.siezLabel.text = String(format: "%.2f GB" ,sum/(1000*1000))
} }
if saveSum < 1024 { if saveSum < 1000 {
self.saveSizeLabel.text = String(format: "%.2f KB" ,(saveSum)) self.saveSizeLabel.text = String(format: "%.2f KB" ,(saveSum))
}else if saveSum < (1024 * 1024) && saveSum > 1024{ }else if saveSum < (1000 * 1000) && saveSum > 1024{
self.saveSizeLabel.text = String(format: "%.2f MB" ,(saveSum/1024)) self.saveSizeLabel.text = String(format: "%.2f MB" ,(saveSum/1000))
}else{ }else{
self.saveSizeLabel.text = String(format: "%.2f GB" ,saveSum/(1024*1024)) self.saveSizeLabel.text = String(format: "%.2f GB" ,saveSum/(1000*1000))
} }
} }
......
...@@ -401,7 +401,7 @@ class CompressViewModel{ ...@@ -401,7 +401,7 @@ class CompressViewModel{
let imageManager = PHCachingImageManager() let imageManager = PHCachingImageManager()
let options = PHImageRequestOptions() let options = PHImageRequestOptions()
options.isSynchronous = false options.isSynchronous = false
options.deliveryMode = .highQualityFormat options.deliveryMode = .opportunistic
options.isNetworkAccessAllowed = true options.isNetworkAccessAllowed = true
imageManager.requestImage(for: asset, targetSize: CGSize(width: 400, height: 400), contentMode: .aspectFill, options: options) { (image, _) in imageManager.requestImage(for: asset, targetSize: CGSize(width: 400, height: 400), contentMode: .aspectFill, options: options) { (image, _) in
......
...@@ -104,12 +104,6 @@ class HomeInfoViewController:BaseViewController { ...@@ -104,12 +104,6 @@ class HomeInfoViewController:BaseViewController {
}) })
} }
// 更新下首页数据以及缓存数据
let dataUpdated = Notification.Name("DataUpdatedNotification")
NotificationCenter.default.post(name: dataUpdated, object: nil, userInfo: nil)
func updateFreeTimes(){ func updateFreeTimes(){
// 删除成功后更新次数 // 删除成功后更新次数
var times = UserDefaults.standard.object(forKey: "saveAdvTimes") as! Int var times = UserDefaults.standard.object(forKey: "saveAdvTimes") as! Int
......
...@@ -624,9 +624,7 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti ...@@ -624,9 +624,7 @@ extension HomePhotosDetailViewController:WaterfallMutiSectionDelegate,UICollecti
// 清理下缓存数据 // 清理下缓存数据
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel) PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel)
// 给首页发通知,数据删除
let dataUpdated = Notification.Name("DataUpdatedNotification")
NotificationCenter.default.post(name: dataUpdated, object: nil, userInfo: nil)
// 更新页面 // 更新页面
......
...@@ -540,9 +540,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie ...@@ -540,9 +540,7 @@ extension HomeVideoDetailController:WaterfallMutiSectionDelegate,UICollectionVie
// 清理下缓存数据 // 清理下缓存数据
PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel) PhotoDataManager.manager.removeDataWhenDeleteInPage(data: self.selectedModel)
// 给首页发通知,数据删除
let dataUpdated = Notification.Name("DataUpdatedNotification")
NotificationCenter.default.post(name: dataUpdated, object: nil, userInfo: nil)
// 更新页面 // 更新页面
......
...@@ -74,16 +74,16 @@ class HomeCollectionViewHeader : UICollectionReusableView { ...@@ -74,16 +74,16 @@ class HomeCollectionViewHeader : UICollectionReusableView {
// 文本 // 文本
self.addSubview(self.tipLabel) self.addSubview(self.tipLabel)
self.tipLabel.snp.makeConstraints { make in self.tipLabel.snp.makeConstraints { make in
make.left.equalToSuperview() make.left.equalToSuperview().offset(8)
make.top.equalToSuperview().offset(4) make.top.equalToSuperview().offset(4)
make.height.equalTo(17) make.height.equalTo(17)
} }
self.addSubview(self.progressBar) self.addSubview(self.progressBar)
self.progressBar.snp.makeConstraints { make in self.progressBar.snp.makeConstraints { make in
make.top.equalTo(self.tipLabel.snp.bottom).offset(12) make.top.equalTo(self.tipLabel.snp.bottom).offset(12)
make.width.equalToSuperview() make.width.equalToSuperview().offset(-16)
make.height.equalTo(31) make.height.equalTo(31)
make.left.equalToSuperview() make.left.equalToSuperview().offset(8)
} }
// self.addSubview(self.subTiplabel) // self.addSubview(self.subTiplabel)
...@@ -163,12 +163,30 @@ class CustomProgressBar: UIView { ...@@ -163,12 +163,30 @@ class CustomProgressBar: UIView {
private let dotSize: CGFloat = 8 private let dotSize: CGFloat = 8
private let labelSpacing: CGFloat = 18 private let labelSpacing: CGFloat = 18
var usedProgress: CGFloat = 0 var usedProgress: CGFloat = 0 {
var chaoticProgress: CGFloat = 0 didSet{
self.updateProgress()
}
}
var totalProgress: CGFloat = 0
var chaoticProgress: CGFloat = 0 {
didSet{
self.updateProgress()
}
}
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
setupUI() setupUI()
let disk = WidgetPublicModel.getDiskSpace()
self.totalProgress = Double(disk.0)
self.usedProgress = Double(disk.0) - Double(disk.1)
Task {
let photoData = await Double(StorageManager.manager.getPhotoResourceMemory())
self.chaoticProgress = photoData
}
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
...@@ -177,22 +195,23 @@ class CustomProgressBar: UIView { ...@@ -177,22 +195,23 @@ class CustomProgressBar: UIView {
} }
private func setupUI() { private func setupUI() {
layer.addSublayer(progressLayer) layer.addSublayer(progressLayer)
usedLabel.text = "Used" usedLabel.text = "Used"
usedLabel.font = UIFont.systemFont(ofSize: 12) usedLabel.font = UIFont.systemFont(ofSize: 12)
usedLabel.textColor = .black usedLabel.textColor = UIColor.colorWithHex(hexStr: black6Color)
addSubview(usedLabel) addSubview(usedLabel)
chaoticLabel.text = "Chaotic content" chaoticLabel.text = "Chaotic content"
chaoticLabel.font = UIFont.systemFont(ofSize: 12) chaoticLabel.font = UIFont.systemFont(ofSize: 12)
chaoticLabel.textColor = .black chaoticLabel.textColor = UIColor.colorWithHex(hexStr: black6Color)
addSubview(chaoticLabel) addSubview(chaoticLabel)
idleLabel.text = "Idle" idleLabel.text = "Idle"
idleLabel.font = UIFont.systemFont(ofSize: 12) idleLabel.font = UIFont.systemFont(ofSize: 12)
idleLabel.textColor = .black idleLabel.textColor = UIColor.colorWithHex(hexStr: black6Color)
addSubview(idleLabel) addSubview(idleLabel)
} }
...@@ -222,16 +241,10 @@ class CustomProgressBar: UIView { ...@@ -222,16 +241,10 @@ class CustomProgressBar: UIView {
} }
private func updateProgress() { private func updateProgress() {
DispatchQueue.global(qos: .userInitiated).async {
let disk = WidgetPublicModel.getDiskSpace()
let usedData = Double(disk.1)
let tolData = Double(disk.0)
Task {
let photoData = await Double(StorageManager.manager.getPhotoResourceMemory())
// 回到主线程更新 UI // 回到主线程更新 UI
DispatchQueue.main.async { DispatchQueue.main.async {
let usedProgress = CGFloat(usedData / tolData) let usedProgress = CGFloat(self.usedProgress / self.totalProgress)
let chaoticProgress = CGFloat(photoData / tolData) let chaoticProgress = CGFloat(self.chaoticProgress / self.totalProgress)
let totalProgress = usedProgress + chaoticProgress let totalProgress = usedProgress + chaoticProgress
let remainingProgress = 1 - totalProgress let remainingProgress = 1 - totalProgress
...@@ -254,8 +267,6 @@ class CustomProgressBar: UIView { ...@@ -254,8 +267,6 @@ class CustomProgressBar: UIView {
self.progressLayer.sublayers = [usedLayer, chaoticLayer, idleLayer] self.progressLayer.sublayers = [usedLayer, chaoticLayer, idleLayer]
} }
} }
}
}
private func drawDot(at point: CGPoint, color: UIColor) { private func drawDot(at point: CGPoint, color: UIColor) {
let dotLayer = CAShapeLayer() let dotLayer = CAShapeLayer()
......
...@@ -37,7 +37,7 @@ class HomeNavView:UIView { ...@@ -37,7 +37,7 @@ class HomeNavView:UIView {
// 标题 // 标题
self.addSubview(self.homeTitle) self.addSubview(self.homeTitle)
self.homeTitle.snp.makeConstraints { make in self.homeTitle.snp.makeConstraints { make in
make.left.equalTo(15) make.left.equalTo(15 + 8)
make.top.equalTo(8 + statusBarHeight) make.top.equalTo(8 + statusBarHeight)
make.height.equalTo(28) make.height.equalTo(28)
make.width.equalTo(149) make.width.equalTo(149)
......
...@@ -84,7 +84,7 @@ class PhotoDataManager { ...@@ -84,7 +84,7 @@ class PhotoDataManager {
} }
for index in 0..<model.titleModelArray.count { for index in 0..<model.titleModelArray.count {
// 删除相似截图和相似视频的缓存 // 删除相似截图和相似视频的缓存
var size :Double = 0.0 var size : Double = 0.0
var finalyVideoData : [[AssetModel]] = [] var finalyVideoData : [[AssetModel]] = []
let array = model.titleModelArray[index].assets let array = model.titleModelArray[index].assets
...@@ -106,6 +106,10 @@ class PhotoDataManager { ...@@ -106,6 +106,10 @@ class PhotoDataManager {
} }
// 处理完成保存下当前数据 // 处理完成保存下当前数据
self.saveToFileSystem(model: model) self.saveToFileSystem(model: model)
// 更新下首页数据以及缓存数据
let dataUpdated = Notification.Name("DataUpdatedNotification")
NotificationCenter.default.post(name: dataUpdated, object: nil, userInfo: nil)
}) })
// 将单利中的数据也删除 // 将单利中的数据也删除
for item in data { for item in data {
......
...@@ -117,13 +117,13 @@ class HomeOtherCollectionCell: UICollectionViewCell { ...@@ -117,13 +117,13 @@ class HomeOtherCollectionCell: UICollectionViewCell {
self.countLabel.text = "\(count) Videos" self.countLabel.text = "\(count) Videos"
} }
// 设置文件大小文字 // 设置文件大小文字
let sizeKB : Double = model.allFileSize/1024 let sizeKB : Double = model.allFileSize/1000
if sizeKB < 1024{ if sizeKB < 1000{
self.sizeLabel.text = String(format: "(%.2lf) KB" ,sizeKB) self.sizeLabel.text = String(format: "(%.2lf) KB" ,sizeKB)
}else if sizeKB < (1024 * 1024) && sizeKB > 1024{ }else if sizeKB < (1000 * 1000) && sizeKB > 1000{
self.sizeLabel.text = String(format: "(%.2lf) MB" ,sizeKB/1024) self.sizeLabel.text = String(format: "(%.2lf) MB" ,sizeKB/1000)
}else{ }else{
self.sizeLabel.text = String(format: "(%.2lf) GB" ,sizeKB/(1024 * 1024)) self.sizeLabel.text = String(format: "(%.2lf) GB" ,sizeKB/(1000 * 1000))
} }
} }
......
...@@ -46,13 +46,13 @@ class HomeVideoDetailCell : UICollectionViewCell { ...@@ -46,13 +46,13 @@ class HomeVideoDetailCell : UICollectionViewCell {
DispatchQueue.main.async { DispatchQueue.main.async {
// 确保在主线程更新UI // 确保在主线程更新UI
self.backImageView.image = thumbnailImage self.backImageView.image = thumbnailImage
let sizeKB : Double = Double(assetSize / 1024) let sizeKB : Double = Double(assetSize / 1000)
if sizeKB < 1024{ if sizeKB < 1000{
self.saveSizeLabel.text = String(format: "%.2f KB" ,sizeKB) self.saveSizeLabel.text = String(format: "%.2f KB" ,sizeKB)
}else if sizeKB < (1024 * 1024) && sizeKB > 1024{ }else if sizeKB < (1000 * 1000) && sizeKB > 1000{
self.saveSizeLabel.text = String(format: "%.2f MB" ,sizeKB/1024) self.saveSizeLabel.text = String(format: "%.2f MB" ,sizeKB/1000)
}else{ }else{
self.saveSizeLabel.text = String(format: "%.2f GB" ,sizeKB/(1024 * 1024)) self.saveSizeLabel.text = String(format: "%.2f GB" ,sizeKB/(1000 * 1000))
} }
} }
} else { } else {
......
...@@ -18,15 +18,17 @@ class PMShowVideoCell: UICollectionViewCell { ...@@ -18,15 +18,17 @@ class PMShowVideoCell: UICollectionViewCell {
var type : Int = 0 var type : Int = 0
func reload() -> Void { func reload() -> Void {
var url : URL var url : URL?
if type == 0 { if type == 0 {
url = "SecretIm".document().appendingPathComponent(playURL) url = "SecretIm".document().appendingPathComponent(playURL)
}else{ }else{
url = homeResouceUrl! url = homeResouceUrl
} }
if let url = url {
player.playVideo(from: url) player.playVideo(from: url)
player.pause() player.pause()
} }
}
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
......
...@@ -185,14 +185,24 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa ...@@ -185,14 +185,24 @@ extension PMShowImgVideoController : UICollectionViewDelegate,UICollectionViewDa
// 相似视频 // 相似视频
if collectionView == MaxCollection { if collectionView == MaxCollection {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowVideoCellID, for: indexPath) as! PMShowVideoCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowVideoCellID, for: indexPath) as! PMShowVideoCell
cell.homeResouceUrl = self.url // 这里主动获取下视频的链接
let ident = self.homeDataSource?[indexPath.row].id?.localIdentifier
if let ident = ident {
self.getVideoURLFromLocalIdentifier(localIdentifier: ident) { videoUrl, error in
if let videoUrl = videoUrl {
cell.homeResouceUrl = videoUrl
DispatchQueue.main.async {
cell.reload()
}
}
}
}
// 表示这个是视频 // 表示这个是视频
cell.type = 1 cell.type = 1
cell.reload()
return cell return cell
}else{ }else{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowItemCellID, for: indexPath) as! PMShowItemCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PMShowItemCellID, for: indexPath) as! PMShowItemCell
cell.icon = self.homeDataSource![indexPath.row].image! cell.icon = self.homeDataSource![indexPath.row].image ?? UIImage()
cell.isCurrent = (self.currentIdx == indexPath.row) cell.isCurrent = (self.currentIdx == indexPath.row)
return cell return cell
} }
......
...@@ -63,9 +63,12 @@ class SecretVideoPlayer: UIView { ...@@ -63,9 +63,12 @@ class SecretVideoPlayer: UIView {
} }
} }
func playVideo(from url: URL) { func playVideo(from url: URL?) {
if url == nil {
return
}
removeObservers() removeObservers()
player = AVPlayer(url: url) player = AVPlayer(url: url!)
if let playerLayer = layer.sublayers?.first as? AVPlayerLayer { if let playerLayer = layer.sublayers?.first as? AVPlayerLayer {
playerLayer.player = player playerLayer.player = player
} }
......
...@@ -20,6 +20,9 @@ class WidgetPublicModel: NSObject { ...@@ -20,6 +20,9 @@ class WidgetPublicModel: NSObject {
return batt return batt
} }
/// 已使用
/// - Returns: 已使用空间
public class func UseDiskSpace() -> CGFloat { public class func UseDiskSpace() -> CGFloat {
let disk = getDiskSpace() let disk = getDiskSpace()
let use = disk.0 - disk.1 let use = disk.0 - disk.1
...@@ -27,6 +30,9 @@ class WidgetPublicModel: NSObject { ...@@ -27,6 +30,9 @@ class WidgetPublicModel: NSObject {
return useP return useP
} }
/// 获取总共和可用空间
/// - Returns: 总共和可用空间
public class func getDiskSpace() -> (Int64,Int64) { public class func getDiskSpace() -> (Int64,Int64) {
let total = TotalDiskSize() let total = TotalDiskSize()
let available = AvailableDiskSize() let available = AvailableDiskSize()
...@@ -43,9 +49,15 @@ class WidgetPublicModel: NSObject { ...@@ -43,9 +49,15 @@ class WidgetPublicModel: NSObject {
} }
// 硬盘剩余大小 // 硬盘剩余大小
class func AvailableDiskSize() -> Int64 { class func AvailableDiskSize() -> Int64 {
var fs = blankof(type: statfs.self) do {
if statfs("/var",&fs) >= 0 { let fileURL = URL(fileURLWithPath: NSHomeDirectory())
return Int64(UInt64(fs.f_bsize) * fs.f_bavail) let values = try fileURL.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey])
if let availableSpace = values.volumeAvailableCapacityForImportantUsage {
return Int64(availableSpace)
}
} catch {
print("获取磁盘空间信息时出错: \(error)")
return -1
} }
return -1 return -1
} }
......
...@@ -135,51 +135,6 @@ class PhotoAndVideoMananger { ...@@ -135,51 +135,6 @@ class PhotoAndVideoMananger {
} }
func fetchAllFile(propress:@escaping (Int,Double) -> Void,completion: @escaping (Double,Int) -> Void) { func fetchAllFile(propress:@escaping (Int,Double) -> Void,completion: @escaping (Double,Int) -> Void) {
// if (self.allAssets.count == 0 ) {
//
// let fetchOptions = PHFetchOptions()
//
// let photoAllAssets = PHAsset.fetchAssets(with: .image, options: fetchOptions)
//
// let videoAllAssets = PHAsset.fetchAssets(with: .video, options: fetchOptions)
//
// let photoAssetsArray = photoAllAssets.objects(at: IndexSet(0..<photoAllAssets.count))
//
// let videoAssetsArray = videoAllAssets.objects(at: IndexSet(0..<videoAllAssets.count))
//
// let combinedArray = photoAssetsArray + videoAssetsArray
//
// DispatchQueue.global().async {[weak self] in
//
// guard let self = self else { return }
// // 计算总大小
// self.calculateTotalSize(of: combinedArray,progress: { fileSiez, index in
// propress(index,Double(fileSiez))
// }, completion: { fileSize,index in
// completion(Double(fileSize),index)
// })
//
// }
//
// }else {
//
//
// let combinedArray = self.allAssets
//
// DispatchQueue.global().async {[weak self] in
//
// guard let self = self else { return }
// // 计算总大小
// self.calculateTotalSize(of: combinedArray,progress: { fileSiez, index in
//
// propress(index,Double(fileSiez))
// }, completion: { fileSize,index in
// completion(Double(fileSize),index)
// })
//
// }
// }
let fetchOptions = PHFetchOptions() let fetchOptions = PHFetchOptions()
let photoAllAssets = PHAsset.fetchAssets(with: .image, options: fetchOptions) let photoAllAssets = PHAsset.fetchAssets(with: .image, options: fetchOptions)
...@@ -517,18 +472,24 @@ class PhotoAndVideoMananger { ...@@ -517,18 +472,24 @@ class PhotoAndVideoMananger {
func getPhotoAssetSize(_ asset: PHAsset, completion: @escaping (Int64) -> Void) { func getPhotoAssetSize(_ asset: PHAsset, completion: @escaping (Int64) -> Void) {
let options = PHImageRequestOptions() let options = PHImageRequestOptions()
options.isSynchronous = false options.isSynchronous = false
options.version = .original // 获取原始数据 // 获取原始数据
options.version = .original
// 不去计算iclound资源
options.isNetworkAccessAllowed = false
PHImageManager.default().requestImageDataAndOrientation(for: asset, options: options) { (data, _, _, _) in PHImageManager.default().requestImageDataAndOrientation(for: asset, options: options) { (data, _, _, _) in
let size = Int64(data?.count ?? 0) let size = Int64(data?.count ?? 0)
completion(size) completion(size)
} }
} }
func getVideoAssetSize(_ asset: PHAsset, completion: @escaping (Int64) -> Void) { func getVideoAssetSize(_ asset: PHAsset, completion: @escaping (Int64) -> Void) {
let options = PHVideoRequestOptions() let options = PHVideoRequestOptions()
// 获取原始数据
options.version = .original options.version = .original
// 不去计算iclound资源
options.isNetworkAccessAllowed = false
PHImageManager.default().requestAVAsset(forVideo: asset, options: options) { (avAsset, _, _) in PHImageManager.default().requestAVAsset(forVideo: asset, options: options) { (avAsset, _, _) in
if let urlAsset = avAsset as? AVURLAsset { if let urlAsset = avAsset as? AVURLAsset {
let size = try? urlAsset.url.resourceValues(forKeys: [.fileSizeKey]).fileSize ?? 0 let size = try? urlAsset.url.resourceValues(forKeys: [.fileSizeKey]).fileSize ?? 0
...@@ -934,7 +895,7 @@ class PhotoAndVideoMananger { ...@@ -934,7 +895,7 @@ class PhotoAndVideoMananger {
// 获取当前版本的照片或视频 // 获取当前版本的照片或视频
options.version = .current options.version = .current
// 尽可能快地提供结果 // 尽可能快地提供结果
options.deliveryMode = .highQualityFormat options.deliveryMode = .fastFormat
// 允许从iCloud请求 // 允许从iCloud请求
options.isNetworkAccessAllowed = true options.isNetworkAccessAllowed = true
// 异步请求 // 异步请求
...@@ -1188,6 +1149,9 @@ class SecretPhotoManager: NSObject, PhotoPickerControllerDelegate , CameraContro ...@@ -1188,6 +1149,9 @@ class SecretPhotoManager: NSObject, PhotoPickerControllerDelegate , CameraContro
PMLoadingHUD.share.disMiss() PMLoadingHUD.share.disMiss()
} }
} else if let error = error { } else if let error = error {
DispatchQueue.main.async {
PMLoadingHUD.share.disMiss()
}
print("删除失败: \(error.localizedDescription)") print("删除失败: \(error.localizedDescription)")
} }
......
...@@ -30,8 +30,8 @@ func formatFileSize(_ bytes: Double) -> String { ...@@ -30,8 +30,8 @@ func formatFileSize(_ bytes: Double) -> String {
var unitIndex = 0 var unitIndex = 0
// 循环计算合适的单位 // 循环计算合适的单位
while size >= 1024 && unitIndex < units.count - 1 { while size >= 1000 && unitIndex < units.count - 1 {
size /= 1024 size /= 1000
unitIndex += 1 unitIndex += 1
} }
......
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 to comment