123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- //
- // Untitled.swift
- // TSLiveWallpaper
- //
- // Created by 100Years on 2025/6/16.
- //
- class TSMineVM {
-
- var target:UIViewController
- init(target: UIViewController) {
- self.target = target
- }
-
-
- lazy var dataArray: [TSBasicSectionModel] = {
- var dataArray = [TSBasicSectionModel]()
- let sectionModel = TSBasicSectionModel()
- dataArray.append(sectionModel)
- // sectionModel.addSubItemModel(
- // createItemModel(
- // leftImage: .mineCellShare,
- // leftTitle: "Update".localized,
- // rightViewStyle: 0,
- // rightString: "",
- // rightIsHave: true,
- // height: 80,
- // rectCorner: .allCorners,
- // tapBlock: { [weak self] _, _, _ in
- // let httpAppStoreLink = "https://apps.apple.com/app/id\(appid)"
- // guard let appStoreURL = URL(string: httpAppStoreLink) else { return }
- //
- // if UIApplication.shared.canOpenURL(appStoreURL) {
- // UIApplication.shared.open(appStoreURL, options: [:], completionHandler: nil)
- // }
- // }))
- sectionModel.addSubItemModel(
- createItemModel(
- leftImage: .mineCellShare,
- leftTitle: "Share us".localized,
- tapBlock: { [weak self] _, _, _ in
- guard let self = self else { return }
- let httpAppStoreLink = "https://apps.apple.com/app/id\(appid)"
- let text = ""
- let url = URL(string: httpAppStoreLink)!
- let image = UIImage(named: "App-Icon")!
- let vc = UIActivityViewController(activityItems: [image, text, url], applicationActivities: nil)
- vc.completionWithItemsHandler = { activity, _, _, _ in
- if let type = activity, type == .copyToPasteboard {
- UIPasteboard.general.string = httpAppStoreLink
- }
- }
- if UIDevice.isPad {
- if let popover = vc.popoverPresentationController {
- popover.sourceView = self.target.view // 设置锚点视图
- popover.sourceRect = CGRect(x: self.target.view.bounds.midX, y: self.target.view.bounds.midY, width: 0, height: 0) // 设置弹窗位置为屏幕中心
- popover.permittedArrowDirections = [] // 禁止箭头指向
- }
- }
- self.target.present(vc, animated: true)
- }))
-
-
- sectionModel.addSubItemModel(
- createItemModel(
- leftImage: .mineCellRateUs,
- leftTitle: "Rate us".localized,
- tapBlock: { [weak self] _, _, _ in
- guard let self = self else { return }
- let appStoreLink = "itms-apps://itunes.apple.com/app/id\(appid)"
- if let url = URL(string: appStoreLink + "?action=write-review"),
- UIApplication.shared.canOpenURL(url) {
- UIApplication.shared.open(url)
- }
- }))
-
- sectionModel.addSubItemModel(
- createItemModel(
- leftImage: .mineCellUseragree,
- leftTitle: "User Agreement".localized,
- tapBlock: { [weak self] _, _, _ in
- guard let self = self else { return }
- let vc = TSBusinessWebVC(urlType: .terms)
- vc.hidesBottomBarWhenPushed = true
- self.target.navigationController?.pushViewController(vc, animated: true)
- }))
-
- sectionModel.addSubItemModel(
- createItemModel(
- leftImage: .mineCellPrivacy,
- leftTitle: "Privacy Policy".localized,
- tapBlock: { [weak self] _, _, _ in
- guard let self = self else { return }
- let vc = TSBusinessWebVC(urlType: .privacy)
- vc.hidesBottomBarWhenPushed = true
- self.target.navigationController?.pushViewController(vc, animated: true)
- }))
- sectionModel.addSubItemModel(updateItem)
- return dataArray
- }()
-
-
- lazy var updateItem: TSBasicItemModel = {
- let itemModel = createItemModel(
- leftImage: .mineCellUpdate,
- leftTitle: "Update".localized,
- rightString: appVersion(),
- rightIsHave: true,
- tapBlock: { [weak self] _, _, _ in
- guard let self = self else { return }
- if let url = URL(string: "https://apps.apple.com/app/id\(appid)"),
- UIApplication.shared.canOpenURL(url) {
- UIApplication.shared.open(url)
- }
- })
- return itemModel
- }()
- }
- extension TSMineVM {
- func createItemModel(
- leftImage:UIImage,
- leftTitle: String,
- rightViewStyle: Int = 0,
- rightString: String = "",
- rightIsHave: Bool = true,
- height: CGFloat = 64,
- tapBlock: @escaping ((TSBasicItemModel, Int, Any?) -> Void))
- -> TSBasicItemModel
- {
- let model = TSBasicItemModel()
- model.leftImage = leftImage
- model.leftTitle = leftTitle
- model.rightViewStyle = rightViewStyle
- model.rightString = rightString
- model.rightIsHave = rightIsHave
- model.height = height
- model.tapBlock = tapBlock
- return model
- }
- }
|