Commit 8255602f authored by yqz's avatar yqz

4-8

parent 784f2c41
......@@ -37,7 +37,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private func setupDefault() {
HomePayModel.share.checkTrialStatus()
NetStatusManager.manager.startNet { status in
switch status {
......
......@@ -217,68 +217,76 @@ class CompressQualityController : BaseViewController{
@objc func submitAction(){
let compressingView : CompressingView = CompressingView(frame: self.view.bounds)
compressingView.data = self.model
self.view.addSubview(compressingView)
// 开始压缩
let manager : CompressViewModel = CompressViewModel()
var currentQulity = 0.2
if currentQulityType == 1 {
currentQulity = 0.5
}
if currentQulityType == 2 {
currentQulity = 0.8
}
var comDataSource : [Data] = []
if self.currentMediaType == 0 {
// 表示压缩图片
manager.compress(assets: self.model!, compressionQuality: currentQulity) {progress in
compressingView.animationView.setProgress(CGFloat(progress), animated: false, duration: 0.1)
} completion: { compressedDataArray, errorArray in
var compressAllSize = 0.0
for (index, data) in compressedDataArray.enumerated() {
if let error = errorArray[index] {
print("第 \(index + 1) 个文件压缩出错: \(error.localizedDescription)")
} else if let data = data {
print("第 \(index + 1) 个文件压缩完成,压缩后大小: \(data.count) 字节")
compressAllSize = compressAllSize + Double(data.count)
comDataSource.append(data)
} else {
print("第 \(index + 1) 个文件压缩失败")
let actionBlock = { [weak self] in
guard let self = self else { return }
let compressingView : CompressingView = CompressingView(frame: self.view.bounds)
compressingView.data = self.model
self.view.addSubview(compressingView)
// 开始压缩
let manager : CompressViewModel = CompressViewModel()
var currentQulity = 0.2
if currentQulityType == 1 {
currentQulity = 0.5
}
if currentQulityType == 2 {
currentQulity = 0.8
}
var comDataSource : [Data] = []
if self.currentMediaType == 0 {
// 表示压缩图片
manager.compress(assets: self.model!, compressionQuality: currentQulity) {progress in
compressingView.animationView.setProgress(CGFloat(progress), animated: false, duration: 0.1)
} completion: { compressedDataArray, errorArray in
var compressAllSize = 0.0
for (index, data) in compressedDataArray.enumerated() {
if let error = errorArray[index] {
print("第 \(index + 1) 个文件压缩出错: \(error.localizedDescription)")
} else if let data = data {
print("第 \(index + 1) 个文件压缩完成,压缩后大小: \(data.count) 字节")
compressAllSize = compressAllSize + Double(data.count)
comDataSource.append(data)
} else {
print("第 \(index + 1) 个文件压缩失败")
}
}
self.updateNextView(compressAllSize,compressingView,comDataSource,[])
}
self.updateNextView(compressAllSize,compressingView,comDataSource,[])
}
}else{
// 压缩视频
var compressAllSize : Double = 0.0
manager.compressVideos(models: self.model!, quality: Float(currentQulity)) { (identifier, progress) in
compressingView.animationView.setProgress(CGFloat(progress), animated: false, duration: 0.1)
} completion: { (outputURLs, errors) in
for (index, outputURL) in outputURLs.enumerated() {
if let outputURL = outputURL {
do {
let attributes = try FileManager.default.attributesOfItem(atPath: outputURL.path)
if let fileSize = attributes[.size] as? Int64 {
compressAllSize = compressAllSize + Double(fileSize)
}else{
// 压缩视频
var compressAllSize : Double = 0.0
manager.compressVideos(models: self.model!, quality: Float(currentQulity)) { (identifier, progress) in
compressingView.animationView.setProgress(CGFloat(progress), animated: false, duration: 0.1)
} completion: { (outputURLs, errors) in
for (index, outputURL) in outputURLs.enumerated() {
if let outputURL = outputURL {
do {
let attributes = try FileManager.default.attributesOfItem(atPath: outputURL.path)
if let fileSize = attributes[.size] as? Int64 {
compressAllSize = compressAllSize + Double(fileSize)
}
} catch {
Print("获取视频文件大小失败")
}
} catch {
Print("获取视频文件大小失败")
print("Compressed video \(index) saved at: \(outputURL)")
} else if let error = errors[index] {
print("Error compressing video \(index): \(error.localizedDescription)")
}
print("Compressed video \(index) saved at: \(outputURL)")
} else if let error = errors[index] {
print("Error compressing video \(index): \(error.localizedDescription)")
}
self.updateNextView(compressAllSize,compressingView,[],outputURLs)
}
self.updateNextView(compressAllSize,compressingView,[],outputURLs)
}
}
}
if HomePayModel.share.isNoAd == false {
HomeNoAdsViewController.show {
actionBlock()
}
}
}
}
......
......@@ -58,10 +58,9 @@ class CompressNavView : UIView {
}
@objc private func proBtnClick() {
let homeNavViewModel = HomeNavViewModel()
let vc = HomePayViewController()
vc.modalPresentationStyle = .fullScreen
homeNavViewModel.presentToDetailController(currentView: self, destnationController: vc)
HomePayViewController.show {
}
}
......
......@@ -56,16 +56,33 @@ class HomeInfoViewController:BaseViewController {
}
}
sview.deleteCallBack = {array in
sview.deleteCallBack = { [weak self] array in
guard let self = self else { return }
if let cA = array as? [String] {
PhotoAndVideoMananger.deleteAssets(localIdentifiers: cA) {[weak self] in
guard let self else {return}
self.tablewView.deleteModel()
let deleteOp:((Any)->Void) = {[weak self] imgs in
if let cA = imgs as? [String] {
PhotoAndVideoMananger.deleteAssets(localIdentifiers: cA) {[weak self] in
guard let self else {return}
self.tablewView.deleteModel()
}
}
}
if HomePayModel.share.isNoAd == false {
if self.type == .duplicates { // 重复
HomePayViewController.show {
deleteOp(array)
}
}else if self.type == .similar { // 相似
HomeNoAdsViewController.show {
deleteOp(array)
}
}else{
HomeNoAdsViewController.show {
deleteOp(array)
}
}
}else {
deleteOp(array)
}
}
......
......@@ -128,15 +128,9 @@ class HomeViewController:BaseViewController {
self.navigationController?.pushViewController(vc, animated: false)
}else {
HomeNoAdsViewController.show()
// if HomePayModel.share.isNoAd == false {
// let vc:HomePayViewController = HomePayViewController()
// let nav:BaseNavViewController = BaseNavViewController(rootViewController: vc)
// nav.modalPresentationStyle = .fullScreen
// self.navigationController?.present(nav, animated: true)
// }
if HomePayModel.share.isNoAd == false {
HomePayViewController.show {}
}
}
}
}
......
......@@ -85,10 +85,9 @@ class HomeNavView:UIView {
}
@objc private func proBtnClick() {
let homeNavViewModel = HomeNavViewModel()
let vc = HomePayViewController()
vc.modalPresentationStyle = .fullScreen
homeNavViewModel.presentToDetailController(currentView: self, destnationController: vc)
HomePayViewController.show {
}
}
......
......@@ -29,6 +29,7 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
func checkTrialStatus() -> Void {
verifyReceiptWithApple { receipt in
self.alert.dismiss()
guard let json = receipt else {
self.refreshReceipt()
return
......@@ -76,11 +77,13 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
else { return }
let payment = SKPayment(product: prod)
SKPaymentQueue.default().add(payment)
alert.show()
}
/** 恢复 */
func restore() -> Void {
SKPaymentQueue.default().restoreCompletedTransactions()
alert.show()
}
override init() {
......@@ -88,6 +91,8 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
SKPaymentQueue.default().add(self)
}
let alert = PMAlertView()
}
extension HomePayModel {
......@@ -105,6 +110,7 @@ extension HomePayModel {
break
case .failed:
Print("购买失败")
alert.dismiss()
SKPaymentQueue.default().finishTransaction(transaction)
break
case .restored:
......
......@@ -148,7 +148,7 @@ class HomePayView:UIView {
}
titleLabel1 = UILabel()
titleLabel1?.text = "Clean your Storage"
titleLabel1?.text = "Clean your storage space"
titleLabel1?.font = UIFont.systemFont(ofSize: 24, weight: .bold)
titleLabel1?.textColor = UIColor.colorWithHex(hexStr: black3Color)
self.addSubview(titleLabel1!)
......@@ -161,7 +161,7 @@ class HomePayView:UIView {
titleLabel1?.sizeToFit()
titleLabel2 = UILabel()
titleLabel2?.text = "Get rid of what you don't need"
titleLabel2?.text = "Delete unnecessary content"
titleLabel2?.font = UIFont.systemFont(ofSize: 14, weight: .bold)
titleLabel2?.textColor = UIColor.colorWithHex(hexStr: black3Color)
self.addSubview(titleLabel2!)
......@@ -287,7 +287,7 @@ class HomePayView:UIView {
}
contentView1Tip1 = UILabel()
contentView1Tip1?.text = "Smart Cleaning, Video Compressor, Secret Storage, Manage Contacts, No Ads and Limits."
contentView1Tip1?.text = "Smart Cleaning, Video Compressor, Secret Storage, No Ads and Limits."
contentView1Tip1?.font = UIFont.systemFont(ofSize: 12, weight: .regular)
contentView1Tip1?.textColor = UIColor.colorWithHex(hexStr: black6Color)
contentView1Tip1?.numberOfLines = 2
......@@ -303,7 +303,6 @@ class HomePayView:UIView {
contentView1Tip1?.setlineSpacing(font: contentView1Tip1!.font, lineSpacing: 3, width: contentView1Tip1!.width, numberOfLines: contentView1Tip1!.numberOfLines, content: contentView1Tip1!.text ?? "")
contentView1Tip2 = UILabel()
contentView1Tip2?.text = "Free for 7 days, then $6.99/week"
contentView1Tip2?.font = UIFont.systemFont(ofSize: 12, weight: .regular)
contentView1Tip2?.textColor = UIColor.colorWithHex(hexStr: black6Color)
contentView1Tip2?.numberOfLines = 1
......@@ -454,7 +453,7 @@ class HomePayView:UIView {
})
freeContentTip = UILabel()
freeContentTip?.text = "7 days free"
freeContentTip?.text = "3 days free"
freeContentTip?.font = UIFont.systemFont(ofSize: 12, weight: .bold)
freeContentTip?.textColor = UIColor.colorWithHex(hexStr: whiteColor)
freeContentTip?.backgroundColor = UIColor.colorWithHex(hexStr: "#52C776")
......@@ -483,7 +482,8 @@ class HomePayView:UIView {
})
normalContentTitle = UILabel()
normalContentTitle?.text = "Due today"
let date:String = Date().operation(1)?.string("MMMM dd yyyy") ?? ""
normalContentTitle?.text = "Due \(date)"
normalContentTitle?.font = UIFont.systemFont(ofSize: 12, weight: .regular)
normalContentTitle?.textColor = UIColor.colorWithHex(hexStr: black6Color)
normalContent?.addSubview(normalContentTitle!)
......@@ -523,6 +523,7 @@ class HomePayView:UIView {
didSet{
guard let prod = product else { return }
normalContentMoney?.text = "$\(prod.price)"
contentView1Tip2?.text = "Free trial for 3 days, $\(prod.price) per year thereafter"
}
}
......
......@@ -14,6 +14,8 @@ class HomePayViewController:UIViewController {
private var homePayView:HomePayView?
private var disjunctor = false
private var doneBlock:(()->Void) = {}
var currentProduct:SKProduct? {
didSet {
setPrice()
......@@ -49,6 +51,7 @@ class HomePayViewController:UIViewController {
switch operstatus {
case .close:
self.dismiss(animated: true)
doneBlock()
default:
break
}
......@@ -122,4 +125,14 @@ extension HomePayViewController {
private func restoreClick() {
HomePayModel.share.restore()
}
class func show( _ compate:@escaping(()->Void)) -> Void {
let vc:HomePayViewController = HomePayViewController()
vc.doneBlock = compate
let nav:BaseNavViewController = BaseNavViewController(rootViewController: vc)
nav.modalPresentationStyle = .fullScreen
guard let rt = UIViewController.topMostViewController() else { return }
rt.present(nav, animated: true)
}
}
......@@ -112,10 +112,10 @@ class SettingViewHeaderCell : UITableViewCell {
}
@objc func leanMoreBtnClick() {
let homeNavViewModel = HomeNavViewModel()
let vc = HomePayViewController()
vc.modalPresentationStyle = .fullScreen
homeNavViewModel.presentToDetailController(currentView: self, destnationController: vc)
HomeNoAdsViewController.show {
}
}
}
......@@ -180,7 +180,7 @@ class SettingViewController : BaseViewController , UITableViewDelegate, UITableV
}
private func PhoneShare() -> Void {
let items: [Any] = [ URL(string: "https://www.baidu.com")!]
let items: [Any] = [ URL(string: "itms-apps://itunes.apple.com/app/id1530333201")! ]
let shareVc = UIActivityViewController(
activityItems: items,
applicationActivities: nil
......
//
// PMAlertView.swift
// PhoneManager
//
// Created by edy on 2025/4/8.
//
import UIKit
class PMAlertView: NSObject {
private var pm_t:String?
private var pm_msg:String?
func show() -> Void {
DispatchQueue.main.async {
guard let rt = UIViewController.topMostViewController() else { return }
self.pmAlert.view.addSubview(self.pm_ActivityIndicator)
self.pm_ActivityIndicator.snp.makeConstraints { make in
make.centerY.centerX.equalToSuperview()
}
rt.present(self.pmAlert, animated: true)
}
}
func dismiss() -> Void {
DispatchQueue.main.async {
self.pmAlert.dismiss(animated: true)
}
}
convenience init(_ title:String?, _ message:String?) {
self.init()
self.pm_t = title
self.pm_msg = message
}
private lazy var pmAlert: UIAlertController = {
let pm = UIAlertController(title: "", message: pm_msg, preferredStyle: .alert)
return pm
}()
private lazy var pm_ActivityIndicator: UIActivityIndicatorView = {
let pmact = UIActivityIndicatorView()
pmact.style = .medium
pmact.startAnimating()
return pmact
}()
}
......@@ -214,3 +214,33 @@ enum GradientDirection {
}
}
}
extension Date {
func string(_ format:String = "") -> String {
let dateforametter = DateFormatter()
dateforametter.dateFormat = format
return dateforametter.string(from: self)
}
func operation(_ year:Int = 0,
_ month:Int = 0,
_ day:Int = 0,
_ houre:Int = 0,
_ minte:Int = 0,
_ sec:Int = 0,
_ week:Int = 0) -> Date? {
let calendar = Calendar.current
let currentDate = self
var dateComponent:DateComponents = calendar.dateComponents([.year,.month,.day,.hour,.minute,.second,.weekday], from: currentDate)
dateComponent.year! += year
dateComponent.month! += month
dateComponent.month! += day
dateComponent.hour! += houre
dateComponent.second! += sec
dateComponent.weekday! += week
guard let toDate = calendar.date(from: dateComponent) else { return self }
return toDate
}
}
......@@ -23,5 +23,40 @@ extension UIViewController {
nav.barHidden = isHidden
}
class func topMostViewController() -> UIViewController? {
guard let rootViewController = UIApplication.shared.keyWindow?.rootViewController else {
return nil
}
return self.topMostViewController(of: rootViewController)
}
private static func topMostViewController(of viewController: UIViewController) -> UIViewController {
// 处理模态弹出的视图控制器
if let presentedViewController = viewController.presentedViewController {
return self.topMostViewController(of: presentedViewController)
}
// 处理 UINavigationController
if let navigationController = viewController as? UINavigationController,
let visibleViewController = navigationController.visibleViewController {
return self.topMostViewController(of: visibleViewController)
}
// 处理 UITabBarController
if let tabBarController = viewController as? UITabBarController,
let selectedViewController = tabBarController.selectedViewController {
return self.topMostViewController(of: selectedViewController)
}
// 处理子控制器
for subview in viewController.view?.subviews ?? [] {
if let childViewController = subview.next as? UIViewController {
return self.topMostViewController(of: childViewController)
}
}
return viewController
}
}
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