|
@@ -202,3 +202,75 @@ extension KMLightMemberManager {
|
|
|
return result
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+//MARK: 登录注册界面弹出逻辑
|
|
|
+/*
|
|
|
+ 弹出策略:
|
|
|
+ 每日首次进入阅读页,自动弹出【注册弹窗】;关闭弹窗后,当日不再弹出,次日零点重置
|
|
|
+ 注意:首次进入阅读页之前,通过其他方式弹出过【注册弹窗】,则进入阅读页不再主动弹出
|
|
|
+ **/
|
|
|
+extension KMLightMemberManager {
|
|
|
+ //检查是否需要弹起注册登录框
|
|
|
+ func checkPopupRegister() -> Bool {
|
|
|
+ var needPop = false
|
|
|
+ self.resetRegisterPopupStatus()
|
|
|
+
|
|
|
+ var info: [String : Any] = [:]
|
|
|
+ if (UserDefaults.standard.value(forKey: "CheckPopupRegistration") == nil) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ info = (UserDefaults.standard.value(forKey: "CheckPopupRegistration") as! [String : Any])
|
|
|
+ }
|
|
|
+
|
|
|
+ let isPopupShownToday = info["isPopupShownToday"] as? Bool ?? false
|
|
|
+ var lastPopupDate = info["lastPopupDate"] as? Date
|
|
|
+
|
|
|
+ // 检查是否已经弹出过注册弹窗
|
|
|
+ if (!isPopupShownToday) {
|
|
|
+ // 获取当前日期
|
|
|
+ let currentDate = Date()
|
|
|
+
|
|
|
+ // 检查上次弹窗显示的日期是否为空,或者不是当天
|
|
|
+ if lastPopupDate == nil || (lastPopupDate != nil &&
|
|
|
+ !Calendar.current.isDate(lastPopupDate!, inSameDayAs: currentDate)) {
|
|
|
+ // 更新上次弹窗显示的日期为当前日期
|
|
|
+ lastPopupDate = currentDate
|
|
|
+ info.updateValue(lastPopupDate!, forKey: "lastPopupDate")
|
|
|
+ info.updateValue(true, forKey: "isPopupShownToday")
|
|
|
+ UserDefaults.standard.set(info, forKey: "CheckPopupRegistration")
|
|
|
+ UserDefaults.standard.synchronize()
|
|
|
+ needPop = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return needPop
|
|
|
+ }
|
|
|
+
|
|
|
+ func resetRegisterPopupStatus() {
|
|
|
+ var info: [String : Any] = [:]
|
|
|
+ if (UserDefaults.standard.value(forKey: "CheckPopupRegistration") == nil) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ info = (UserDefaults.standard.value(forKey: "CheckPopupRegistration") as! [String : Any])
|
|
|
+ }
|
|
|
+
|
|
|
+ var isPopupShownToday = info["isPopupShownToday"]
|
|
|
+ let lastPopupDate = info["lastPopupDate"] as? Date
|
|
|
+
|
|
|
+ // 获取当前日期和时间
|
|
|
+ let currentDate = Date()
|
|
|
+ // 获取当前日历
|
|
|
+ let calendar = Calendar.current
|
|
|
+ // 获取当天的午夜时间
|
|
|
+ let midnight = calendar.startOfDay(for: currentDate)
|
|
|
+ // 检查上次弹窗显示的日期是否早于当天的午夜时间
|
|
|
+ if let lastPopupDate = lastPopupDate, lastPopupDate < midnight {
|
|
|
+ // 重置弹窗状态
|
|
|
+ isPopupShownToday = false
|
|
|
+
|
|
|
+ info.updateValue(isPopupShownToday!, forKey: "isPopupShownToday")
|
|
|
+// info.updateValue(NSDate(), forKey: "lastPopupDate")
|
|
|
+ UserDefaults.standard.set(info, forKey: "CheckPopupRegistration")
|
|
|
+ UserDefaults.standard.synchronize()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|