QSLGuideusersToCommentManager.swift 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. //
  2. // QSLGuideusersToCommentManager.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2025/7/31.
  6. //
  7. import Foundation
  8. import UIKit
  9. enum QSLGuideusersToCommentType : Int{
  10. case member //会员
  11. case nonMember // 非会员
  12. }
  13. class QSLGuideusersToCommentManager: NSObject {
  14. static let commentShare = QSLGuideusersToCommentManager()
  15. var guideGobalModel: QSLGuideIsTriggeredModel = QSLGuideIsTriggeredModel()
  16. var commentType: QSLGuideusersToCommentType = .member
  17. private var timer: Timer?
  18. // Initialize and setup notifications
  19. override init() {
  20. super.init()
  21. setupAppStateNotifications()
  22. startTimer()
  23. }
  24. deinit {
  25. stopTimer()
  26. NotificationCenter.default.removeObserver(self)
  27. }
  28. // MARK: - Timer Management
  29. private func setupAppStateNotifications() {
  30. NotificationCenter.default.addObserver(self,
  31. selector: #selector(appDidEnterBackground),
  32. name: UIApplication.didEnterBackgroundNotification,
  33. object: nil)
  34. NotificationCenter.default.addObserver(self,
  35. selector: #selector(appWillEnterForeground),
  36. name: UIApplication.willEnterForegroundNotification,
  37. object: nil)
  38. }
  39. @objc private func appWillEnterForeground() {
  40. startTimer()
  41. }
  42. @objc private func appDidEnterBackground() {
  43. stopTimer()
  44. }
  45. private func startTimer() {
  46. //print("startTimersfsdf---A--\(self.commentType)")
  47. // Invalidate existing timer if any
  48. stopTimer()
  49. // Create new timer that fires every minute
  50. timer = Timer.scheduledTimer(withTimeInterval: 60.0, repeats: true) { [weak self] _ in
  51. self?.timerFired()
  52. }
  53. // Fire immediately on first start
  54. timerFired()
  55. }
  56. private func stopTimer() {
  57. //print("startTimersfsdf---B--\(self.commentType)")
  58. timer?.invalidate()
  59. timer = nil
  60. }
  61. private func timerFired() {
  62. // Call your existing method here
  63. manageWhetherTriggerPopUpWindow(commentType)
  64. }
  65. // MARK: - Existing Methods (unchanged)
  66. //管理处理是否触发好评引导弹窗
  67. func manageWhetherTriggerPopUpWindow(_ showType: QSLGuideusersToCommentType) {
  68. //print("startTimersfsdf---C--\(showType)---\(self.commentType)")
  69. QSLNetwork().request(.guideIsTriggered(dict: [String: Any]())) { response in
  70. let guideIsModel: QSLGuideIsTriggeredModel = response.mapObject(QSLGuideIsTriggeredModel.self, modelKey: "data")
  71. self.commentType = showType
  72. self.guideGobalModel = guideIsModel
  73. if guideIsModel.trigger {
  74. if showType == .member {
  75. DispatchQueue.main.async {
  76. self.memberPositiveReviewPopWindow()
  77. }
  78. } else {
  79. DispatchQueue.main.async {
  80. self.noMemberPositiveReviewPopWindow()
  81. }
  82. }
  83. }
  84. } fail: { code, msg in
  85. }
  86. }
  87. ///领取好评引导奖励请求
  88. func requestForReceivingGoodReviewGuidance() {
  89. QSLNetwork().request(.guideReceiveReward(dict: [String: Any]())) { response in
  90. if self.commentType == .member {
  91. DispatchQueue.main.async {
  92. self.popUpWindowForMemberReview()
  93. }
  94. } else {
  95. DispatchQueue.main.async {
  96. self.popUpWindowForNonMemberReviews()
  97. }
  98. }
  99. } fail: { code, msg in
  100. }
  101. }
  102. }
  103. //管理各种类型的痰喘
  104. extension QSLGuideusersToCommentManager {
  105. ///会员的好评弹窗
  106. @MainActor func memberPositiveReviewPopWindow() {
  107. // 创建深灰色文本样式
  108. let darkGrayAttributes: [NSAttributedString.Key: Any] = [
  109. .foregroundColor: UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0),
  110. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  111. .paragraphStyle: {
  112. let paragraphStyle = NSMutableParagraphStyle()
  113. paragraphStyle.alignment = .center
  114. return paragraphStyle
  115. }(),
  116. .kern: -1
  117. ]
  118. // 创建绿色文本样式
  119. let greenAttributes: [NSAttributedString.Key: Any] = [
  120. .foregroundColor: UIColor(red: 17/255.0, green: 186/255.0, blue: 152/255.0, alpha: 1.0),
  121. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  122. .paragraphStyle: {
  123. let paragraphStyle = NSMutableParagraphStyle()
  124. paragraphStyle.alignment = .center
  125. return paragraphStyle
  126. }(),
  127. .kern: -1
  128. ]
  129. let inputtr = NSMutableAttributedString()
  130. let titleOneAttr = NSAttributedString(string: "五星好评,", attributes: darkGrayAttributes)
  131. let titleTwoAttr = NSAttributedString(string: "多送\(self.guideGobalModel.extraMemberDays)天会员", attributes: greenAttributes)
  132. inputtr.append(titleOneAttr)
  133. inputtr.append(titleTwoAttr)
  134. if let currentWindow = UIApplication.keyWindow {
  135. QSLVipAlertView.alert(view: currentWindow, title: "", titleAttring: inputtr, content: "你的一条五星好评是我们前进的动力", isOneBtn: true, oneBtnText: "立即好评", oneBtnClosure: { [weak self] in
  136. // 同步调用
  137. QSLInAppReviewmanager.requestReview()
  138. DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  139. self?.requestForReceivingGoodReviewGuidance()
  140. }
  141. })
  142. }
  143. }
  144. ///非会员的好评弹窗
  145. @MainActor func noMemberPositiveReviewPopWindow() {
  146. // 创建深灰色文本样式
  147. let darkGrayAttributes: [NSAttributedString.Key: Any] = [
  148. .foregroundColor: UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0),
  149. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  150. .paragraphStyle: {
  151. let paragraphStyle = NSMutableParagraphStyle()
  152. paragraphStyle.alignment = .center
  153. return paragraphStyle
  154. }(),
  155. .kern: -1
  156. ]
  157. let inputtr = NSMutableAttributedString()
  158. let titleOneAttr = NSAttributedString(string: "给我们一个好评呗~", attributes: darkGrayAttributes)
  159. inputtr.append(titleOneAttr)
  160. if let currentWindow = UIApplication.keyWindow {
  161. QSLVipAlertView.alert(view: currentWindow, title: "", titleAttring: inputtr, content: "我们将回馈用户更多的优惠福利", isOneBtn: true, oneBtnText: "立即好评", oneBtnClosure: { [weak self] in
  162. // 同步调用
  163. QSLInAppReviewmanager.requestReview()
  164. // 延迟1秒执行
  165. DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  166. self?.requestForReceivingGoodReviewGuidance()
  167. }
  168. //self?.requestAddFri()
  169. })
  170. }
  171. }
  172. ///会员好评的结果弹窗
  173. @MainActor func popUpWindowForMemberReview() {
  174. // 创建深灰色文本样式
  175. let darkGrayAttributes: [NSAttributedString.Key: Any] = [
  176. .foregroundColor: UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0),
  177. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  178. .paragraphStyle: {
  179. let paragraphStyle = NSMutableParagraphStyle()
  180. paragraphStyle.alignment = .center
  181. return paragraphStyle
  182. }(),
  183. .kern: -1
  184. ]
  185. // 创建绿色文本样式
  186. let greenAttributes: [NSAttributedString.Key: Any] = [
  187. .foregroundColor: UIColor(red: 17/255.0, green: 186/255.0, blue: 152/255.0, alpha: 1.0),
  188. .font: UIFont(name: "Noto Sans SC", size: 28)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 28, weight: .black),
  189. .paragraphStyle: {
  190. let paragraphStyle = NSMutableParagraphStyle()
  191. paragraphStyle.alignment = .center
  192. return paragraphStyle
  193. }(),
  194. .kern: -1
  195. ]
  196. let inputtr = NSMutableAttributedString()
  197. let titleOneAttr = NSAttributedString(string: "你已成功增加", attributes: darkGrayAttributes)
  198. let titleTwoAttr = NSAttributedString(string: " \(self.guideGobalModel.extraMemberDays) ", attributes: greenAttributes)
  199. let titleThreeAttr = NSAttributedString(string: "天会员", attributes: darkGrayAttributes)
  200. inputtr.append(titleOneAttr)
  201. inputtr.append(titleTwoAttr)
  202. inputtr.append(titleThreeAttr)
  203. if let currentWindow = UIApplication.keyWindow {
  204. QSLVipResultsAlertView.alert(view: currentWindow, title: "", titleAttring: inputtr, content: "恭喜你,领取成功!", isOneBtn: true, oneBtnText: "我知道了", oneBtnClosure: { [weak self] in
  205. //self?.requestAddFri()
  206. })
  207. }
  208. }
  209. ///非会员好评的结果弹窗
  210. @MainActor func popUpWindowForNonMemberReviews() {
  211. ///标题
  212. let titleDarkGrayAttributes: [NSAttributedString.Key: Any] = [
  213. .foregroundColor: UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0),
  214. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  215. .paragraphStyle: {
  216. let paragraphStyle = NSMutableParagraphStyle()
  217. paragraphStyle.alignment = .center
  218. return paragraphStyle
  219. }(),
  220. .kern: -1
  221. ]
  222. // 创建深灰色文本样式
  223. let darkGrayAttributes: [NSAttributedString.Key: Any] = [
  224. .foregroundColor: UIColor(red: 255/255.0, green: 230/255.0, blue: 192/255.0, alpha: 1.0),
  225. .font: UIFont(name: "Noto Sans SC", size: 16)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  226. .paragraphStyle: {
  227. let paragraphStyle = NSMutableParagraphStyle()
  228. paragraphStyle.alignment = .center
  229. return paragraphStyle
  230. }(),
  231. .kern: -1
  232. ]
  233. // 创建绿色文本样式
  234. let greenAttributes: [NSAttributedString.Key: Any] = [
  235. .foregroundColor: UIColor(red: 255/255.0, green: 230/255.0, blue: 192/255.0, alpha: 1.0),
  236. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 28, weight: .black),
  237. .paragraphStyle: {
  238. let paragraphStyle = NSMutableParagraphStyle()
  239. paragraphStyle.alignment = .center
  240. return paragraphStyle
  241. }(),
  242. .kern: -1
  243. ]
  244. let inputtr = NSMutableAttributedString()
  245. let titleOneAttr = NSAttributedString(string: "感谢支持~", attributes: titleDarkGrayAttributes)
  246. inputtr.append(titleOneAttr)
  247. let contentAtter = NSMutableAttributedString()
  248. let contentAtterOne = NSAttributedString(string: "会员套餐体验", attributes: darkGrayAttributes)
  249. contentAtter.append(contentAtterOne)
  250. let contentAtterTwo = NSAttributedString(string: " \(self.guideGobalModel.returnDaysBasedOnRegistration())+\(self.guideGobalModel.extraMemberDays) ", attributes: greenAttributes)
  251. contentAtter.append(contentAtterTwo)
  252. let contentAtterTherr = NSAttributedString(string: "天", attributes: darkGrayAttributes)
  253. contentAtter.append(contentAtterTherr)
  254. if let currentWindow = UIApplication.keyWindow {
  255. QSLVipResultsNoMemberAlertView.alert(view: currentWindow, title: "", titleAttring: inputtr, content: "已解锁会员套餐体验7+3福利套餐",bottomContentAttring: contentAtter, isOneBtn: true, oneBtnText: "立即查看", oneBtnClosure: { [weak self] in
  256. QSLJumpManager.shared.pushToVip(type: .guideComments)
  257. })
  258. }
  259. }
  260. }