123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // TSSetingViewModel.swift
- // AIEmoji
- //
- // Created by 100Years on 2025/1/16.
- //
- import StoreKit
- class TSSetingViewModel: ObservableObject {
-
- @Published var settingTypes: [SettingType] = SettingType.allCases
- @Published var isViper: Bool = PurchaseManager.default.isVip
- @Published var isHaveNewVersion: Bool = false
-
- var appid = "6740220736"
- // todo.kailen-privacy
- func showPrivacy(parent: UIViewController) {
- let vc = TSBusinessWebVC(urlType: .privacy)
- vc.hidesBottomBarWhenPushed = true
- parent.navigationController?.pushViewController(vc, animated: true)
- }
- // todo.kailen-Agreement
- func showAgreement(parent: UIViewController) {
- let vc = TSBusinessWebVC(urlType: .terms)
- vc.hidesBottomBarWhenPushed = true
- parent.navigationController?.pushViewController(vc, animated: true)
- }
- // todo.kailen-logo
- func shareApp(parent: UIViewController) {
- let httpAppStoreLink = "https://apps.apple.com/app/id\(appid)"
- let text = "Space"
- let url = URL(string: httpAppStoreLink)!
- let image = UIImage(named: "App-Icon")!.compressImageSize(to: CGSize(width: 100, height: 100))
- let final = ShareActivityItemProvider(placeholderItem: image)
- let vc = UIActivityViewController(activityItems: [url, final, text], applicationActivities: nil)
- vc.completionWithItemsHandler = { activity, _, _, _ in
- if let type = activity, type == .copyToPasteboard {
- UIPasteboard.general.string = httpAppStoreLink
- }
- }
- parent.present(vc, animated: true)
-
- }
-
- func updateApp(parent: UIViewController) {
- let httpAppStoreLink = "https://apps.apple.com/app/id\(appid)"
- if let url = URL(string: httpAppStoreLink),
- UIApplication.shared.canOpenURL(url) {
- UIApplication.shared.open(url)
- }
- }
-
- func rateAction() {
- let countKey = "ProcessCompletedCountKey"
- // If the app doesn't store the count, this returns 0.
- var count = UserDefaults.standard.integer(forKey: countKey)
- count += 1
- UserDefaults.standard.set(count, forKey: countKey)
- /// 如果当前版本 弹过一次 那么下一次就走url
- /// 如果当前版本 没弹过,那就弹
- if count >= 4 {
- let openStr = "itms-apps://itunes.apple.com/app/\(appid)?action=write-review"
- if let url = URL(string: openStr), UIApplication.shared.canOpenURL(url) {
- if #available(iOS 10.0, *) {
- UIApplication.shared.open(url, options: [:], completionHandler: nil)
- } else {
- UIApplication.shared.canOpenURL(url)
- }
- } else {
- print("链接出错")
- }
- } else {
- SKStoreReviewController.requestReview()
- }
- }
-
- // todo.kailen-logo
- func pushTutorials(parent: UIViewController) {
- let vc = TSEmojisTutorialsVC()
- vc.hidesBottomBarWhenPushed = true
- parent.navigationController?.pushViewController(vc, animated: true)
- }
-
- // todo.kailen-logo
- func pushVipPurchase(parent: UIViewController) {
- TSPurchaseVC.show(target: parent) {[weak self] in
- guard let self = self else { return }
- isViper = PurchaseManager.default.isVip
- }
- }
-
- func removeCloudData(parent: UIViewController) {
- TSToastShared.showLoading(containerView: parent.view)
- kDelayOnMainThread(5) {
- TSToastShared.hideLoading()
- kSaveSuccesswShared.show(atView: parent.view,text: "Removed Successfully".localized,showViewBtn: false)
- }
-
- #if DEBUG
- // TSAbnormalPopUpAlertVC.showRobotWarning()
- // guard let window = WindowHelper.getKeyWindow() else {
- // debugPrint("getKeyWindow nil")
- // return
- // }
- // let topY = k_Nav_Height+10
- // debugPrint("topY=\(topY)")
- // kSaveSuccesswShared.show(atView: window,text: "Successfully generated".localized,deadline: 5.0,bottom: kSaveSuccesswShared.getBottom(topY: topY)) {
- // }
- //
- // TSRMShared.textPtpDBHistory()
- #endif
- }
-
- func AboutData(parent: UIViewController) {
- let vc = TSAboutDataVC()
- vc.hidesBottomBarWhenPushed = true
- parent.navigationController?.pushViewController(vc, animated: true)
- }
- }
- extension UIImage {
- // 压缩图片到指定尺寸
- func compressImageSize(to size: CGSize) -> UIImage {
- let targetSize = size
- if self.size.width > targetSize.width || self.size.height > targetSize.height {
- return kf.resize(to: targetSize)
- }
- return self
- }
- }
|