|
@@ -15,7 +15,7 @@
|
|
|
|
|
|
/**
|
|
|
@abstract 测试模式,默认为false
|
|
|
- */
|
|
|
+ */
|
|
|
@objc public var debug: Bool = false
|
|
|
|
|
|
/**
|
|
@@ -24,7 +24,7 @@
|
|
|
@param subscribeType 订阅状态,可单独在configuration设置
|
|
|
@param platform 平台
|
|
|
@return
|
|
|
- */
|
|
|
+ */
|
|
|
@objc public func initConfig(appName: KMAdvertisementAppNameType,
|
|
|
subscribeType:KMAdvertisementSubscribeType,
|
|
|
platform: KMAdvertisementPlatformType) {
|
|
@@ -32,18 +32,18 @@
|
|
|
}
|
|
|
|
|
|
private class InternalImplementation {
|
|
|
- fileprivate var privateProperty: String = "Hidden"
|
|
|
- fileprivate func internalMethod() {
|
|
|
- // 实现细节
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private let internalImplementation = InternalImplementation()
|
|
|
-
|
|
|
- public func publicMethod() {
|
|
|
- // 使用内部实现
|
|
|
- internalImplementation.internalMethod()
|
|
|
+ fileprivate var privateProperty: String = "Hidden"
|
|
|
+ fileprivate func internalMethod() {
|
|
|
+ // 实现细节
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private let internalImplementation = InternalImplementation()
|
|
|
+
|
|
|
+ public func publicMethod() {
|
|
|
+ // 使用内部实现
|
|
|
+ internalImplementation.internalMethod()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension KMAdvertisementManager {
|
|
@@ -52,7 +52,7 @@ extension KMAdvertisementManager {
|
|
|
@abstract 获取数据
|
|
|
@param data 传入参数 类型为KMAdvertisementModel
|
|
|
@return
|
|
|
- */
|
|
|
+ */
|
|
|
@objc public func fetchData(completion: @escaping (_ data: KMAdvertisementInfo?, _ error:Error?) -> Void) -> Void {
|
|
|
self.fetchDataWithResponseObject { data, responseObject, error in
|
|
|
if completion != nil {
|
|
@@ -74,21 +74,21 @@ extension KMAdvertisementManager {
|
|
|
"app_version": version]
|
|
|
|
|
|
//先拿缓存数据 再请求新数据
|
|
|
- let cacheData = KMAdvertisementCache.default.readData()
|
|
|
- if cacheData.count != 0 {
|
|
|
- for model in cacheData {
|
|
|
- let jsonString: String = (model["detail"] as? String) ?? ""
|
|
|
- let jsonData: Data = jsonString.data(using: .utf8)!
|
|
|
- let dict = try?JSONSerialization.jsonObject(with: jsonData)
|
|
|
- infoDict = dict as! NSDictionary
|
|
|
- }
|
|
|
- self.parseData(data: cacheData, isNeedLocalComparison: true) { result in
|
|
|
- if result.count != 0 {
|
|
|
- info = result.first!
|
|
|
- completion(result.first, nil, nil)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+// let cacheData = KMAdvertisementCache.default.readData()
|
|
|
+// if cacheData.count != 0 {
|
|
|
+// for model in cacheData {
|
|
|
+// let jsonString: String = (model["detail"] as? String) ?? ""
|
|
|
+// let jsonData: Data = jsonString.data(using: .utf8)!
|
|
|
+// let dict = try?JSONSerialization.jsonObject(with: jsonData)
|
|
|
+// infoDict = dict as! NSDictionary
|
|
|
+// }
|
|
|
+// self.parseData(data: cacheData, isNeedLocalComparison: true) { result in
|
|
|
+// if result.count != 0 {
|
|
|
+// info = result.first!
|
|
|
+// completion(result.first, nil, nil)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
unowned let weakSelf = self
|
|
|
KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { [self] task, responseObject, error in
|
|
@@ -201,29 +201,6 @@ extension KMAdvertisementManager {
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
- // func allowLoadContentData(data: KMAdvertisementModel) -> Bool {
|
|
|
- // var result = false
|
|
|
- //
|
|
|
- // let time: NSInteger = NSInteger(KMAdvertisementTimeStampConversion.getCurrentTimeInterval())!
|
|
|
- // let startTime: NSInteger = NSInteger(data.startTime!)!
|
|
|
- // let endTime: NSInteger = NSInteger(data.endTime!)!
|
|
|
- // let platform = configuration.platform
|
|
|
- // let subscribeType = configuration.subscribeType
|
|
|
- // let version = data.version ?? "1.0"
|
|
|
- // let localVersion = self.getLocalVersion()
|
|
|
- // let hidden = data.hidden ?? false
|
|
|
- //
|
|
|
- // if (time >= startTime &&
|
|
|
- // time <= endTime &&
|
|
|
- // platform == data.platform &&
|
|
|
- // self.compareVersion(nowVersion:localVersion, newVersion: version) &&
|
|
|
- // (subscribeType == data.subscribeType || data.subscribeType == .all) &&
|
|
|
- // !hidden) {
|
|
|
- // result = true
|
|
|
- // }
|
|
|
- // return result
|
|
|
- // }
|
|
|
-
|
|
|
//过滤item是否显示
|
|
|
func allowLoadItemData(_ data: KMAdvertisementInfo) -> KMAdvertisementInfo {
|
|
|
let advertisement = data.advertisement
|
|
@@ -241,6 +218,21 @@ extension KMAdvertisementManager {
|
|
|
recommondContent?.recommondContentPDFPro = recommondContentPDFPro
|
|
|
data.recommondContent = recommondContent
|
|
|
|
|
|
+ let topRightInfoContent = data.topRightInfoContent
|
|
|
+ if let content = topRightInfoContent?.content {
|
|
|
+ topRightInfoContent?.content = self.canShow(data: content)
|
|
|
+ }
|
|
|
+
|
|
|
+ let loginViewContent = data.loginViewContent
|
|
|
+ if let content = loginViewContent?.content {
|
|
|
+ loginViewContent?.content = self.canShow(data: content)
|
|
|
+ }
|
|
|
+
|
|
|
+ let userViewInfoContent = data.userViewInfoContent
|
|
|
+ if let content = userViewInfoContent?.content {
|
|
|
+ userViewInfoContent?.content = self.canShow(data: content)
|
|
|
+ }
|
|
|
+
|
|
|
return data;
|
|
|
}
|
|
|
|
|
@@ -262,7 +254,7 @@ extension KMAdvertisementManager {
|
|
|
canAdd = false
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if canAdd {
|
|
|
dataArray.append(item)
|
|
|
}
|
|
@@ -272,61 +264,6 @@ extension KMAdvertisementManager {
|
|
|
return dataArray
|
|
|
}
|
|
|
|
|
|
-// + (BOOL)checkAdvertisementValid:(KMRecommondInfo *)info {
|
|
|
-// #if DEBUG
|
|
|
-// [[NSUserDefaults standardUserDefaults] removeObjectForKey:info.versionKey];
|
|
|
-// #endif
|
|
|
-// if ([[NSUserDefaults standardUserDefaults] objectForKey:info.versionKey]) {
|
|
|
-// return NO;
|
|
|
-// }
|
|
|
-// if (!info.show) {
|
|
|
-// return NO;
|
|
|
-// }
|
|
|
-// if (info.showType == KMRecommondShowType_Lite) {
|
|
|
-// if ([[IAPProductsManager defaultManager] isAvailableAllFunction]) {
|
|
|
-// return NO;
|
|
|
-// }
|
|
|
-// } else if (info.showType == KMRecommondShowType_Pro) {
|
|
|
-// if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
|
|
|
-// return NO;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return YES;
|
|
|
-// }
|
|
|
-
|
|
|
-// func allowLoadItemData(_ data: KMAdvertisementModel) -> KMAdvertisementModel {
|
|
|
-// //获取缓存数据
|
|
|
-// if (UserDefaults.standard.object(forKey: "KMAdvertisementShowScroll_iOS") == nil) {
|
|
|
-// UserDefaults.standard.set([], forKey: "KMAdvertisementShowScroll_iOS")
|
|
|
-// }
|
|
|
-// let cacheArray: [String] = UserDefaults.standard.object(forKey: "KMAdvertisementShowScroll_iOS") as! [String]
|
|
|
-//
|
|
|
-// let model = data
|
|
|
-// var sections: [KMAdvertisementModelSection] = []
|
|
|
-// for section in data.content! {
|
|
|
-// var items: [KMAdvertisementModelItem] = []
|
|
|
-// for item in section.content! {
|
|
|
-// let timeString = KMAdvertisementTimeStampConversion.getCurrentTimeInterval()
|
|
|
-// let time: NSInteger = NSInteger(timeString)!
|
|
|
-// let startTime: NSInteger = NSInteger(item.startTime ?? timeString)!
|
|
|
-// let endTime: NSInteger = NSInteger(item.endTime ?? timeString)!
|
|
|
-// let hidden = item.hidden ?? false
|
|
|
-//
|
|
|
-//// print(hidden ? "隐藏" : "显示")
|
|
|
-// if (!hidden &&
|
|
|
-// time >= startTime &&
|
|
|
-// time <= endTime &&
|
|
|
-// !cacheArray.contains(item.productID ?? "")) {
|
|
|
-// items.append(item)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// section.content = items
|
|
|
-// sections.append(section)
|
|
|
-// }
|
|
|
-// model.content = sections
|
|
|
-// return model
|
|
|
-// }
|
|
|
-
|
|
|
//获取本地版本号
|
|
|
func getLocalVersion() -> String {
|
|
|
var localVersion = ""
|
|
@@ -362,9 +299,9 @@ extension KMAdvertisementManager {
|
|
|
|
|
|
extension KMAdvertisementManager {
|
|
|
static func checkAdvertisementValid(_ info: KMAdvertisementItemInfo) -> Bool {
|
|
|
- #if DEBUG
|
|
|
+#if DEBUG
|
|
|
UserDefaults.standard.removeObject(forKey: info.version ?? "")
|
|
|
- #endif
|
|
|
+#endif
|
|
|
|
|
|
if UserDefaults.standard.object(forKey: info.version ?? "") != nil {
|
|
|
return false
|
|
@@ -377,14 +314,12 @@ extension KMAdvertisementManager {
|
|
|
let currentTime = Int(NSDate.init().timeIntervalSince1970 * 1000)
|
|
|
if currentTime > Int(info.startTime ?? "0") ?? currentTime &&
|
|
|
currentTime < Int(info.endTime ?? "0") ?? currentTime {
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if info.subscriptionType == "1" {
|
|
|
-// if IAPProductsManager.default().isAvailableAllFunction() {
|
|
|
if IAPProductsManager.default().isAvailableAllFunction() == true {
|
|
|
return false
|
|
|
}
|