TSMineVM.swift 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // Untitled.swift
  3. // TSLiveWallpaper
  4. //
  5. // Created by 100Years on 2025/6/16.
  6. //
  7. class TSMineVM {
  8. var target:UIViewController
  9. init(target: UIViewController) {
  10. self.target = target
  11. }
  12. lazy var dataArray: [TSBasicSectionModel] = {
  13. var dataArray = [TSBasicSectionModel]()
  14. let sectionModel = TSBasicSectionModel()
  15. dataArray.append(sectionModel)
  16. // sectionModel.addSubItemModel(
  17. // createItemModel(
  18. // leftImage: .mineCellShare,
  19. // leftTitle: "Update".localized,
  20. // rightViewStyle: 0,
  21. // rightString: "",
  22. // rightIsHave: true,
  23. // height: 80,
  24. // rectCorner: .allCorners,
  25. // tapBlock: { [weak self] _, _, _ in
  26. // let httpAppStoreLink = "https://apps.apple.com/app/id\(appid)"
  27. // guard let appStoreURL = URL(string: httpAppStoreLink) else { return }
  28. //
  29. // if UIApplication.shared.canOpenURL(appStoreURL) {
  30. // UIApplication.shared.open(appStoreURL, options: [:], completionHandler: nil)
  31. // }
  32. // }))
  33. sectionModel.addSubItemModel(
  34. createItemModel(
  35. leftImage: .mineCellShare,
  36. leftTitle: "Share us".localized,
  37. tapBlock: { [weak self] _, _, _ in
  38. guard let self = self else { return }
  39. let httpAppStoreLink = "https://apps.apple.com/app/id\(appid)"
  40. let text = ""
  41. let url = URL(string: httpAppStoreLink)!
  42. let image = UIImage(named: "App-Icon")!
  43. let vc = UIActivityViewController(activityItems: [image, text, url], applicationActivities: nil)
  44. vc.completionWithItemsHandler = { activity, _, _, _ in
  45. if let type = activity, type == .copyToPasteboard {
  46. UIPasteboard.general.string = httpAppStoreLink
  47. }
  48. }
  49. if UIDevice.isPad {
  50. if let popover = vc.popoverPresentationController {
  51. popover.sourceView = self.target.view // 设置锚点视图
  52. popover.sourceRect = CGRect(x: self.target.view.bounds.midX, y: self.target.view.bounds.midY, width: 0, height: 0) // 设置弹窗位置为屏幕中心
  53. popover.permittedArrowDirections = [] // 禁止箭头指向
  54. }
  55. }
  56. self.target.present(vc, animated: true)
  57. }))
  58. sectionModel.addSubItemModel(
  59. createItemModel(
  60. leftImage: .mineCellRateUs,
  61. leftTitle: "Rate us".localized,
  62. tapBlock: { [weak self] _, _, _ in
  63. guard let self = self else { return }
  64. let appStoreLink = "itms-apps://itunes.apple.com/app/id\(appid)"
  65. if let url = URL(string: appStoreLink + "?action=write-review"),
  66. UIApplication.shared.canOpenURL(url) {
  67. UIApplication.shared.open(url)
  68. }
  69. }))
  70. sectionModel.addSubItemModel(
  71. createItemModel(
  72. leftImage: .mineCellUseragree,
  73. leftTitle: "User Agreement".localized,
  74. tapBlock: { [weak self] _, _, _ in
  75. guard let self = self else { return }
  76. let vc = TSBusinessWebVC(urlType: .terms)
  77. vc.hidesBottomBarWhenPushed = true
  78. self.target.navigationController?.pushViewController(vc, animated: true)
  79. }))
  80. sectionModel.addSubItemModel(
  81. createItemModel(
  82. leftImage: .mineCellPrivacy,
  83. leftTitle: "Privacy Policy".localized,
  84. tapBlock: { [weak self] _, _, _ in
  85. guard let self = self else { return }
  86. let vc = TSBusinessWebVC(urlType: .privacy)
  87. vc.hidesBottomBarWhenPushed = true
  88. self.target.navigationController?.pushViewController(vc, animated: true)
  89. }))
  90. sectionModel.addSubItemModel(updateItem)
  91. return dataArray
  92. }()
  93. lazy var updateItem: TSBasicItemModel = {
  94. let itemModel = createItemModel(
  95. leftImage: .mineCellUpdate,
  96. leftTitle: "Update".localized,
  97. rightString: appVersion(),
  98. rightIsHave: true,
  99. tapBlock: { [weak self] _, _, _ in
  100. guard let self = self else { return }
  101. if let url = URL(string: "https://apps.apple.com/app/id\(appid)"),
  102. UIApplication.shared.canOpenURL(url) {
  103. UIApplication.shared.open(url)
  104. }
  105. })
  106. return itemModel
  107. }()
  108. }
  109. extension TSMineVM {
  110. func createItemModel(
  111. leftImage:UIImage,
  112. leftTitle: String,
  113. rightViewStyle: Int = 0,
  114. rightString: String = "",
  115. rightIsHave: Bool = true,
  116. height: CGFloat = 64,
  117. tapBlock: @escaping ((TSBasicItemModel, Int, Any?) -> Void))
  118. -> TSBasicItemModel
  119. {
  120. let model = TSBasicItemModel()
  121. model.leftImage = leftImage
  122. model.leftTitle = leftTitle
  123. model.rightViewStyle = rightViewStyle
  124. model.rightString = rightString
  125. model.rightIsHave = rightIsHave
  126. model.height = height
  127. model.tapBlock = tapBlock
  128. return model
  129. }
  130. }