QSLGuideusersToCommentManager.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 isClose = false
  16. //归因渠道
  17. public var clickCompanyChannel : String = ""
  18. var guideGobalModel: QSLGuideIsTriggeredModel = QSLGuideIsTriggeredModel()
  19. var commentType: QSLGuideusersToCommentType = .member
  20. private var timer: Timer?
  21. var closeBtnClosure: (() -> ())?
  22. override init() {
  23. super.init()
  24. setupAppStateNotifications()
  25. }
  26. deinit {
  27. NotificationCenter.default.removeObserver(self)
  28. }
  29. // MARK: - Timer Management
  30. private func setupAppStateNotifications() {
  31. NotificationCenter.default.addObserver(
  32. self,
  33. selector: #selector(windowDidBecomeKey),
  34. name: UIWindow.didBecomeKeyNotification,
  35. object: nil)
  36. }
  37. @objc func windowDidBecomeKey(notification: Notification) {
  38. if(self.isClose){
  39. return
  40. }
  41. self.closeBtnClosure?()
  42. }
  43. // MARK: - Existing Methods (unchanged)
  44. //管理处理是否触发好评引导弹窗
  45. func manageWhetherTriggerPopUpWindow(_ showType: QSLGuideusersToCommentType, closeBtnClosure: @escaping () -> () = {}) {
  46. self.closeBtnClosure = closeBtnClosure
  47. QSLNetwork().request(.guideIsTriggered(dict: [String: Any]())) { response in
  48. let guideIsModel: QSLGuideIsTriggeredModel = response.mapObject(QSLGuideIsTriggeredModel.self, modelKey: "data")
  49. self.commentType = showType
  50. self.guideGobalModel = guideIsModel
  51. if guideIsModel.trigger{
  52. DispatchQueue.main.async {
  53. QSLInAppReviewmanager.requestReview()
  54. }
  55. }else{
  56. closeBtnClosure()
  57. }
  58. } fail: { code, msg in
  59. }
  60. }
  61. //判断是不是这两个渠道 ASA渠道和自然流量两个渠道
  62. func areThisTwoChannel() -> Bool {
  63. if self.clickCompanyChannel == "Apple Search Ads" || self.clickCompanyChannel == "natural" {
  64. return false
  65. }
  66. return true
  67. }
  68. ///领取好评引导奖励请求
  69. func requestForReceivingGoodReviewGuidance() {
  70. QSLNetwork().request(.guideReceiveReward(dict: [String: Any]())) { response in
  71. if self.commentType == .member {
  72. DispatchQueue.main.async {
  73. self.popUpWindowForMemberReview()
  74. }
  75. } else {
  76. DispatchQueue.main.async {
  77. self.popUpWindowForNonMemberReviews()
  78. }
  79. }
  80. } fail: { code, msg in
  81. }
  82. }
  83. }
  84. //管理各种类型的弹窗
  85. extension QSLGuideusersToCommentManager {
  86. ///会员的好评弹窗
  87. @MainActor func memberPositiveReviewPopWindow() {
  88. // 创建深灰色文本样式
  89. let darkGrayAttributes: [NSAttributedString.Key: Any] = [
  90. .foregroundColor: UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0),
  91. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  92. .paragraphStyle: {
  93. let paragraphStyle = NSMutableParagraphStyle()
  94. paragraphStyle.alignment = .center
  95. return paragraphStyle
  96. }(),
  97. .kern: -1
  98. ]
  99. // 创建绿色文本样式
  100. let greenAttributes: [NSAttributedString.Key: Any] = [
  101. .foregroundColor: UIColor(red: 17/255.0, green: 186/255.0, blue: 152/255.0, alpha: 1.0),
  102. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  103. .paragraphStyle: {
  104. let paragraphStyle = NSMutableParagraphStyle()
  105. paragraphStyle.alignment = .center
  106. return paragraphStyle
  107. }(),
  108. .kern: -1
  109. ]
  110. let inputtr = NSMutableAttributedString()
  111. let titleOneAttr = NSAttributedString(string: "五星好评,", attributes: darkGrayAttributes)
  112. let titleTwoAttr = NSAttributedString(string: "多送\(self.guideGobalModel.extraMemberDays)天会员", attributes: greenAttributes)
  113. inputtr.append(titleOneAttr)
  114. inputtr.append(titleTwoAttr)
  115. if let currentWindow = UIApplication.keyWindow {
  116. QSLVipAlertView.alert(view: currentWindow, title: "", titleAttring: inputtr, content: "你的一条五星好评是我们前进的动力", isOneBtn: true, oneBtnText: "立即好评", oneBtnClosure: {
  117. // 同步调用
  118. QSLInAppReviewmanager.requestReview()
  119. /*DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
  120. self?.requestForReceivingGoodReviewGuidance()
  121. }*/
  122. })
  123. }
  124. }
  125. ///非会员的好评弹窗
  126. @MainActor func noMemberPositiveReviewPopWindow(closeBtnClosure: @escaping () -> () = {}) {
  127. // 创建深灰色文本样式
  128. let darkGrayAttributes: [NSAttributedString.Key: Any] = [
  129. .foregroundColor: UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0),
  130. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  131. .paragraphStyle: {
  132. let paragraphStyle = NSMutableParagraphStyle()
  133. paragraphStyle.alignment = .center
  134. return paragraphStyle
  135. }(),
  136. .kern: -1
  137. ]
  138. let inputtr = NSMutableAttributedString()
  139. let titleOneAttr = NSAttributedString(string: "给我们一个好评呗~", attributes: darkGrayAttributes)
  140. inputtr.append(titleOneAttr)
  141. if let currentWindow = UIApplication.keyWindow {
  142. QSLVipAlertView.alert(view: currentWindow, title: "", titleAttring: inputtr, content: "我们将回馈用户更多的优惠福利", isOneBtn: true, oneBtnText: "立即好评", oneBtnClosure: {
  143. // 同步调用
  144. QSLInAppReviewmanager.requestReview()
  145. },closeBtnClosure: {
  146. closeBtnClosure()
  147. })
  148. }
  149. }
  150. ///会员好评的结果弹窗
  151. @MainActor func popUpWindowForMemberReview() {
  152. // 创建深灰色文本样式
  153. let darkGrayAttributes: [NSAttributedString.Key: Any] = [
  154. .foregroundColor: UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0),
  155. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  156. .paragraphStyle: {
  157. let paragraphStyle = NSMutableParagraphStyle()
  158. paragraphStyle.alignment = .center
  159. return paragraphStyle
  160. }(),
  161. .kern: -1
  162. ]
  163. // 创建绿色文本样式
  164. let greenAttributes: [NSAttributedString.Key: Any] = [
  165. .foregroundColor: UIColor(red: 17/255.0, green: 186/255.0, blue: 152/255.0, alpha: 1.0),
  166. .font: UIFont(name: "Noto Sans SC", size: 28)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 28, weight: .black),
  167. .paragraphStyle: {
  168. let paragraphStyle = NSMutableParagraphStyle()
  169. paragraphStyle.alignment = .center
  170. return paragraphStyle
  171. }(),
  172. .kern: -1
  173. ]
  174. let inputtr = NSMutableAttributedString()
  175. let titleOneAttr = NSAttributedString(string: "你已成功增加", attributes: darkGrayAttributes)
  176. let titleTwoAttr = NSAttributedString(string: " \(self.guideGobalModel.extraMemberDays) ", attributes: greenAttributes)
  177. let titleThreeAttr = NSAttributedString(string: "天会员", attributes: darkGrayAttributes)
  178. inputtr.append(titleOneAttr)
  179. inputtr.append(titleTwoAttr)
  180. inputtr.append(titleThreeAttr)
  181. if let currentWindow = UIApplication.keyWindow {
  182. QSLVipResultsAlertView.alert(view: currentWindow, title: "", titleAttring: inputtr, content: "恭喜你,领取成功!", isOneBtn: true, oneBtnText: "我知道了", oneBtnClosure: { [weak self] in
  183. //self?.requestAddFri()
  184. })
  185. }
  186. }
  187. ///非会员好评的结果弹窗
  188. @MainActor func popUpWindowForNonMemberReviews() {
  189. ///标题
  190. let titleDarkGrayAttributes: [NSAttributedString.Key: Any] = [
  191. .foregroundColor: UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0),
  192. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  193. .paragraphStyle: {
  194. let paragraphStyle = NSMutableParagraphStyle()
  195. paragraphStyle.alignment = .center
  196. return paragraphStyle
  197. }(),
  198. .kern: -1
  199. ]
  200. // 创建深灰色文本样式
  201. let darkGrayAttributes: [NSAttributedString.Key: Any] = [
  202. .foregroundColor: UIColor(red: 255/255.0, green: 230/255.0, blue: 192/255.0, alpha: 1.0),
  203. .font: UIFont(name: "Noto Sans SC", size: 16)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 20, weight: .black),
  204. .paragraphStyle: {
  205. let paragraphStyle = NSMutableParagraphStyle()
  206. paragraphStyle.alignment = .center
  207. return paragraphStyle
  208. }(),
  209. .kern: -1
  210. ]
  211. // 创建绿色文本样式
  212. let greenAttributes: [NSAttributedString.Key: Any] = [
  213. .foregroundColor: UIColor(red: 255/255.0, green: 230/255.0, blue: 192/255.0, alpha: 1.0),
  214. .font: UIFont(name: "Noto Sans SC", size: 20)?.withTraits(traits: .traitBold) ?? UIFont.systemFont(ofSize: 28, weight: .black),
  215. .paragraphStyle: {
  216. let paragraphStyle = NSMutableParagraphStyle()
  217. paragraphStyle.alignment = .center
  218. return paragraphStyle
  219. }(),
  220. .kern: -1
  221. ]
  222. let inputtr = NSMutableAttributedString()
  223. let titleOneAttr = NSAttributedString(string: "感谢支持~", attributes: titleDarkGrayAttributes)
  224. inputtr.append(titleOneAttr)
  225. let contentAtter = NSMutableAttributedString()
  226. let contentAtterOne = NSAttributedString(string: "会员套餐体验", attributes: darkGrayAttributes)
  227. contentAtter.append(contentAtterOne)
  228. let contentAtterTwo = NSAttributedString(string: " \(self.guideGobalModel.returnDaysBasedOnRegistration())+\(self.guideGobalModel.extraMemberDays) ", attributes: greenAttributes)
  229. contentAtter.append(contentAtterTwo)
  230. let contentAtterTherr = NSAttributedString(string: "天", attributes: darkGrayAttributes)
  231. contentAtter.append(contentAtterTherr)
  232. if let currentWindow = UIApplication.keyWindow {
  233. QSLVipResultsNoMemberAlertView.alert(view: currentWindow, title: "", titleAttring: inputtr, content: "已解锁会员套餐体验7+3福利套餐",bottomContentAttring: contentAtter, isOneBtn: true, oneBtnText: "立即查看", oneBtnClosure: { [weak self] in
  234. QSLJumpManager.shared.pushToVip(type: .guideComments)
  235. })
  236. }
  237. }
  238. }