TSSetingViewModel.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // TSSetingViewModel.swift
  3. // AIEmoji
  4. //
  5. // Created by 100Years on 2025/1/16.
  6. //
  7. import StoreKit
  8. class TSSetingViewModel: ObservableObject {
  9. @Published var settingTypes: [SettingType] = SettingType.allCases
  10. @Published var isViper: Bool = PurchaseManager.default.isVip
  11. @Published var isHaveNewVersion: Bool = false
  12. var appid = "6740220736"
  13. // todo.kailen-privacy
  14. func showPrivacy(parent: UIViewController) {
  15. let vc = TSBusinessWebVC(urlType: .privacy)
  16. vc.hidesBottomBarWhenPushed = true
  17. parent.navigationController?.pushViewController(vc, animated: true)
  18. }
  19. // todo.kailen-Agreement
  20. func showAgreement(parent: UIViewController) {
  21. let vc = TSBusinessWebVC(urlType: .terms)
  22. vc.hidesBottomBarWhenPushed = true
  23. parent.navigationController?.pushViewController(vc, animated: true)
  24. }
  25. // todo.kailen-logo
  26. func shareApp(parent: UIViewController) {
  27. let httpAppStoreLink = "https://apps.apple.com/app/id\(appid)"
  28. let text = "Space"
  29. let url = URL(string: httpAppStoreLink)!
  30. let image = UIImage(named: "App-Icon")!.compressImageSize(to: CGSize(width: 100, height: 100))
  31. let final = ShareActivityItemProvider(placeholderItem: image)
  32. let vc = UIActivityViewController(activityItems: [url, final, text], applicationActivities: nil)
  33. vc.completionWithItemsHandler = { activity, _, _, _ in
  34. if let type = activity, type == .copyToPasteboard {
  35. UIPasteboard.general.string = httpAppStoreLink
  36. }
  37. }
  38. parent.present(vc, animated: true)
  39. }
  40. func updateApp(parent: UIViewController) {
  41. let httpAppStoreLink = "https://apps.apple.com/app/id\(appid)"
  42. if let url = URL(string: httpAppStoreLink),
  43. UIApplication.shared.canOpenURL(url) {
  44. UIApplication.shared.open(url)
  45. }
  46. }
  47. func rateAction() {
  48. let countKey = "ProcessCompletedCountKey"
  49. // If the app doesn't store the count, this returns 0.
  50. var count = UserDefaults.standard.integer(forKey: countKey)
  51. count += 1
  52. UserDefaults.standard.set(count, forKey: countKey)
  53. /// 如果当前版本 弹过一次 那么下一次就走url
  54. /// 如果当前版本 没弹过,那就弹
  55. if count >= 4 {
  56. let openStr = "itms-apps://itunes.apple.com/app/\(appid)?action=write-review"
  57. if let url = URL(string: openStr), UIApplication.shared.canOpenURL(url) {
  58. if #available(iOS 10.0, *) {
  59. UIApplication.shared.open(url, options: [:], completionHandler: nil)
  60. } else {
  61. UIApplication.shared.canOpenURL(url)
  62. }
  63. } else {
  64. print("链接出错")
  65. }
  66. } else {
  67. SKStoreReviewController.requestReview()
  68. }
  69. }
  70. // todo.kailen-logo
  71. func pushTutorials(parent: UIViewController) {
  72. let vc = TSEmojisTutorialsVC()
  73. vc.hidesBottomBarWhenPushed = true
  74. parent.navigationController?.pushViewController(vc, animated: true)
  75. }
  76. // todo.kailen-logo
  77. func pushVipPurchase(parent: UIViewController) {
  78. TSPurchaseVC.show(target: parent) {[weak self] in
  79. guard let self = self else { return }
  80. isViper = PurchaseManager.default.isVip
  81. }
  82. }
  83. func removeCloudData(parent: UIViewController) {
  84. TSToastShared.showLoading(containerView: parent.view)
  85. kDelayOnMainThread(5) {
  86. TSToastShared.hideLoading()
  87. kSaveSuccesswShared.show(atView: parent.view,text: "Removed Successfully".localized,showViewBtn: false)
  88. }
  89. #if DEBUG
  90. // TSAbnormalPopUpAlertVC.showRobotWarning()
  91. // guard let window = WindowHelper.getKeyWindow() else {
  92. // debugPrint("getKeyWindow nil")
  93. // return
  94. // }
  95. // let topY = k_Nav_Height+10
  96. // debugPrint("topY=\(topY)")
  97. // kSaveSuccesswShared.show(atView: window,text: "Successfully generated".localized,deadline: 5.0,bottom: kSaveSuccesswShared.getBottom(topY: topY)) {
  98. // }
  99. //
  100. // TSRMShared.textPtpDBHistory()
  101. #endif
  102. }
  103. func AboutData(parent: UIViewController) {
  104. let vc = TSAboutDataVC()
  105. vc.hidesBottomBarWhenPushed = true
  106. parent.navigationController?.pushViewController(vc, animated: true)
  107. }
  108. }
  109. extension UIImage {
  110. // 压缩图片到指定尺寸
  111. func compressImageSize(to size: CGSize) -> UIImage {
  112. let targetSize = size
  113. if self.size.width > targetSize.width || self.size.height > targetSize.height {
  114. return kf.resize(to: targetSize)
  115. }
  116. return self
  117. }
  118. }