Browse Source

【接口】向下兼容

lizhe 2 years ago
parent
commit
e276c54a35

+ 1 - 0
KMAdvertisement/KMAdvertisementCache/KMAdvertisementCache.swift

@@ -32,6 +32,7 @@ class KMAdvertisementCache: NSObject {
 
    //读取
     func readData() -> [NSDictionary] {
+        print("数据地址 = " + (kFilePath.expandingTildeInPath as String))
         let data =  NSArray.init(contentsOfFile: kFilePath.expandingTildeInPath as String)
         if (data != nil) {
             return data as! [NSDictionary]

+ 9 - 1
KMAdvertisement/KMAdvertisementManager.swift

@@ -66,7 +66,15 @@ extension KMAdvertisementManager {
      @param data 传入参数 类型为KMAdvertisementModel
      @return
       */
-    @objc public func fetchData(completion:@escaping (_ data: [KMAdvertisementModel]?, _ responseObject: AnyObject?, _ error:Error?) -> Void) -> Void {
+    @objc public func fetchData(completion: @escaping (_ data: [KMAdvertisementModel]?, _ error:Error?) -> Void) -> Void {
+        self.fetchDataWithResponseObject { data, responseObject, error in
+            if completion != nil {
+                completion(data, error)
+            }
+        }
+    }
+    
+    @objc public func fetchDataWithResponseObject(completion:@escaping (_ data: [KMAdvertisementModel]?, _ responseObject: AnyObject? , _ error:Error?) -> Void) -> Void {
         print("开始获取数据")
         var version: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString").debugDescription
         if (version.count == 0) {

+ 4 - 6
KMAdvertisementDemo_Mac/ViewController.swift

@@ -32,7 +32,7 @@ class ViewController: NSViewController {
         KMAdvertisementManager.manager.debug = true
         
         //获取广告数据
-        KMAdvertisementManager.manager.fetchData { [unowned self] data, responseObject, error in
+        KMAdvertisementManager.manager.fetchDataWithResponseObject { [unowned self] data, responseObject, error in
             if data != nil {
                 for model in data! {
                     if model.showType == .list {
@@ -53,14 +53,14 @@ class ViewController: NSViewController {
                         } _: { data in
                             print("数据刷新了")
                         }
-                        
+
                         //视图加载方法二
                         self.tableView.inputData = model
                         self.tableView.actionCompletion = {actionType, actionItem in
                             print("list 2")
                         }
                     }
-                    
+
                     if model.showType == .view {
                         //视图加载方法一
                         let view =  KMAdvertisementManager.manager.show(type: KMAdvertisementShowType.view, data: model, superView: self.showView) { actionType, actionItem in
@@ -68,7 +68,7 @@ class ViewController: NSViewController {
                         } _: { data in
                             print("数据刷新了")
                         }
-                        
+
                         //视图加载方法二
                         if self.advertisementView != nil {
                             self.advertisementView.inputData = model
@@ -80,8 +80,6 @@ class ViewController: NSViewController {
                 }
             }
         }
-        
-        
     }
 
     override var representedObject: Any? {