Bladeren bron

【2025】【Home】广告模块点击完善

niehaoyu 4 maanden geleden
bovenliggende
commit
607b7d54dc

+ 3 - 11
PDF Office/PDF Master/Class/KMAdvertisement/Manager/KMAdvertisementManager.swift

@@ -150,16 +150,8 @@ extension KMAdvertisementManager {
                     //                decoder.keyDecodingStrategy = .convertFromSnakeCase //带下划线命名
                     
                     decoder.nonConformingFloatDecodingStrategy = .convertFromString(positiveInfinity: "+∞", negativeInfinity: "-∞", nan: "NaN")
-#if DEBUG
-                    print(dict)
-                    //MARK: 测试使用
-                    var advertisementModel = try! decoder.decode(KMAdvertisementInfo.self, from: jsonData)
-                    if (self.allowLoadContentData(data: advertisementModel)) {
-                        resultArray.append(self.allowLoadItemData(advertisementModel))
-                        isNeedSave = true
-                    }
-#else
-                    //            MARK: 此处try 使用 ? ,如果数据出问题 advertisementModel将无参数, 测试时使用!
+                    
+                    // MARK: 此处try 使用 ? ,如果数据出问题 advertisementModel将无参数, 测试时使用!
                     var advertisementModel = try? decoder.decode(KMAdvertisementInfo.self, from: jsonData)
                     if (advertisementModel != nil) {
                         if (self.allowLoadContentData(data: advertisementModel!)) {
@@ -167,7 +159,7 @@ extension KMAdvertisementManager {
                             isNeedSave = true
                         }
                     }
-#endif
+                    
                 }
             }
         }

+ 28 - 3
PDF Office/PDF Master/KMClass/KMHomeViewController/Views/KMHomeRecommondView/KMHomeRecommondView.swift

@@ -147,10 +147,16 @@ class KMHomeRecommondView: BaseXibView {
         } else {
             adsView.isHidden = false
             let adsData = KMAdvertisementManager.manager.info.advertisement?.content
-             guard let model = adsData?.first else {
+            guard let model = adsData?.first else {
                 adsView.isHidden = true
                 return
             }
+            if let versionKey = model.version {
+                if UserDefaults.standard.object(forKey: versionKey) != nil {
+                    adsView.isHidden = true
+                    return
+                }
+            }
             let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: model.image, highlight: false))
             self.adsImageView.image = KMAdvertisementImage.imageWithURL(url: url, completion: { [weak self] image in
                 self?.adsImageView.image = image
@@ -195,9 +201,28 @@ class KMHomeRecommondView: BaseXibView {
         }
     }
     
-    @IBAction func closeAdsImageview(_ sender: Any) {
+    @IBAction func adsViewClicked(_ sender: Any) {
+        let adsData = KMAdvertisementManager.manager.info.advertisement?.content
+        guard let model = adsData?.first else {
+            adsView.isHidden = true
+            return
+        }
+        
+        let string = KMAdvertisementModelTransition.transitionLanguage(langeuage: model.linkURL)
+        if string.count != 0  {
+            NSWorkspace.shared.open(URL.init(string: string)!)
+        }
+        if let versionKey = model.version {
+            UserDefaults.standard.set("show", forKey: versionKey)
+            UserDefaults.standard.synchronize()
+        }
         
+        self.adsView.isHidden = true
+    }
+     
+    @IBAction func closeAdsImageview(_ sender: Any) {
+        self.adsView.isHidden = true
+         
     }
-    
     
 }

+ 14 - 0
PDF Office/PDF Master/KMClass/KMHomeViewController/Views/KMHomeRecommondView/KMHomeRecommondView.xib

@@ -76,6 +76,16 @@
                                     <rect key="frame" x="0.0" y="0.0" width="208" height="117"/>
                                     <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="f9F-42-U0L"/>
                                 </imageView>
+                                <button translatesAutoresizingMaskIntoConstraints="NO" id="7xN-4F-4Dx">
+                                    <rect key="frame" x="0.0" y="0.0" width="208" height="117"/>
+                                    <buttonCell key="cell" type="bevel" bezelStyle="rounded" alignment="center" imageScaling="proportionallyDown" inset="2" id="4pQ-2v-thQ">
+                                        <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+                                        <font key="font" metaFont="system"/>
+                                    </buttonCell>
+                                    <connections>
+                                        <action selector="adsViewClicked:" target="-2" id="6kx-zI-hqR"/>
+                                    </connections>
+                                </button>
                                 <button translatesAutoresizingMaskIntoConstraints="NO" id="GtZ-J5-weo">
                                     <rect key="frame" x="186" y="95" width="16" height="16"/>
                                     <buttonCell key="cell" type="bevel" bezelStyle="rounded" image="ads_closeBtn" imagePosition="only" alignment="center" imageScaling="proportionallyDown" inset="2" id="xJ8-sU-9Ro">
@@ -92,10 +102,14 @@
                                 </button>
                             </subviews>
                             <constraints>
+                                <constraint firstItem="7xN-4F-4Dx" firstAttribute="top" secondItem="ESC-nr-GbN" secondAttribute="top" id="1V5-qX-Pc9"/>
                                 <constraint firstAttribute="trailing" secondItem="PK4-eH-K8G" secondAttribute="trailing" id="3cu-Xp-DQx"/>
                                 <constraint firstItem="GtZ-J5-weo" firstAttribute="top" secondItem="ESC-nr-GbN" secondAttribute="top" constant="6" id="95J-G2-ffA"/>
                                 <constraint firstAttribute="bottom" secondItem="PK4-eH-K8G" secondAttribute="bottom" id="9s4-xM-QAo"/>
                                 <constraint firstItem="PK4-eH-K8G" firstAttribute="top" secondItem="ESC-nr-GbN" secondAttribute="top" id="Dti-ct-XvM"/>
+                                <constraint firstAttribute="trailing" secondItem="7xN-4F-4Dx" secondAttribute="trailing" id="Hgk-sP-jA2"/>
+                                <constraint firstAttribute="bottom" secondItem="7xN-4F-4Dx" secondAttribute="bottom" id="QFF-DA-I0Z"/>
+                                <constraint firstItem="7xN-4F-4Dx" firstAttribute="leading" secondItem="ESC-nr-GbN" secondAttribute="leading" id="e8Q-U6-E4a"/>
                                 <constraint firstAttribute="width" constant="208" id="kfG-1F-rqI"/>
                                 <constraint firstItem="PK4-eH-K8G" firstAttribute="leading" secondItem="ESC-nr-GbN" secondAttribute="leading" id="mfZ-hB-sdH"/>
                                 <constraint firstAttribute="height" constant="117" id="pwC-8G-4Yk"/>