فهرست منبع

fix:优化加入定时器进行询问是否弹框。

“HeShaoZe” 4 ماه پیش
والد
کامیت
994e49ef72
1فایلهای تغییر یافته به همراه70 افزوده شده و 14 حذف شده
  1. 70 14
      QuickSearchLocation/Classes/Common/Tool/QSLGuideusersToCommentManager.swift

+ 70 - 14
QuickSearchLocation/Classes/Common/Tool/QSLGuideusersToCommentManager.swift

@@ -15,21 +15,80 @@ enum QSLGuideusersToCommentType : Int{
 class QSLGuideusersToCommentManager: NSObject {
     
     static let commentShare = QSLGuideusersToCommentManager()
-
-    var guideGobalModel : QSLGuideIsTriggeredModel = QSLGuideIsTriggeredModel()
     
-    var commentType : QSLGuideusersToCommentType = .member
+    var guideGobalModel: QSLGuideIsTriggeredModel = QSLGuideIsTriggeredModel()
+    var commentType: QSLGuideusersToCommentType = .member
+    private var timer: Timer?
+    
+    // Initialize and setup notifications
+    override init() {
+        super.init()
+        setupAppStateNotifications()
+        startTimer()
+    }
+    
+    deinit {
+        stopTimer()
+        NotificationCenter.default.removeObserver(self)
+    }
+    
+    // MARK: - Timer Management
+    
+    private func setupAppStateNotifications() {
+        NotificationCenter.default.addObserver(self,
+                                             selector: #selector(appDidEnterBackground),
+                                             name: UIApplication.didEnterBackgroundNotification,
+                                             object: nil)
+        NotificationCenter.default.addObserver(self,
+                                             selector: #selector(appWillEnterForeground),
+                                             name: UIApplication.willEnterForegroundNotification,
+                                             object: nil)
+    }
+    
+    @objc private func appWillEnterForeground() {
+        startTimer()
+    }
+    
+    @objc private func appDidEnterBackground() {
+        stopTimer()
+    }
+    
+    private func startTimer() {
+        //print("startTimersfsdf---A--\(self.commentType)")
+        // Invalidate existing timer if any
+        stopTimer()
+        
+        // Create new timer that fires every minute
+        timer = Timer.scheduledTimer(withTimeInterval: 60.0, repeats: true) { [weak self] _ in
+            self?.timerFired()
+        }
+        
+        // Fire immediately on first start
+        timerFired()
+    }
+    
+    private func stopTimer() {
+        //print("startTimersfsdf---B--\(self.commentType)")
+        timer?.invalidate()
+        timer = nil
+    }
+    
+    private func timerFired() {
+        // Call your existing method here
+        manageWhetherTriggerPopUpWindow(commentType)
+    }
+    
+    // MARK: - Existing Methods (unchanged)
     
     //管理处理是否触发好评引导弹窗
-    func manageWhetherTriggerPopUpWindow(_ showType : QSLGuideusersToCommentType) {
-        //print("showTypesdfsdfs---\(showType)")
-        QSLNetwork().request(.guideIsTriggered(dict: [String : Any]())) { response in
-            //print("responsesfsdfsf-----\(response)---\(showType)")
-            let guideIsModel : QSLGuideIsTriggeredModel = response.mapObject(QSLGuideIsTriggeredModel.self, modelKey: "data")
+    func manageWhetherTriggerPopUpWindow(_ showType: QSLGuideusersToCommentType) {
+        //print("startTimersfsdf---C--\(showType)---\(self.commentType)")
+        QSLNetwork().request(.guideIsTriggered(dict: [String: Any]())) { response in
+            let guideIsModel: QSLGuideIsTriggeredModel = response.mapObject(QSLGuideIsTriggeredModel.self, modelKey: "data")
             self.commentType = showType
             self.guideGobalModel = guideIsModel
-            if (guideIsModel.trigger) {
-                if  showType == .member {
+            if guideIsModel.trigger {
+                if showType == .member {
                     DispatchQueue.main.async {
                         self.memberPositiveReviewPopWindow()
                     }
@@ -39,15 +98,13 @@ class QSLGuideusersToCommentManager: NSObject {
                     }
                 }
             }
-            
         } fail: { code, msg in
-            //print("failsfdsdfsdf-----\(code)---\(code)")
         }
     }
     
     ///领取好评引导奖励请求
     func requestForReceivingGoodReviewGuidance() {
-        QSLNetwork().request(.guideReceiveReward(dict: [String : Any]())) { response in
+        QSLNetwork().request(.guideReceiveReward(dict: [String: Any]())) { response in
             if self.commentType == .member {
                 DispatchQueue.main.async {
                     self.popUpWindowForMemberReview()
@@ -59,7 +116,6 @@ class QSLGuideusersToCommentManager: NSObject {
             }
         } fail: { code, msg in
         }
-
     }
 }