Browse Source

【订阅】Appstore 价格显示

lizhe 1 year ago
parent
commit
83ca14e0f2

+ 1 - 1
PDF Office/PDF Master/Class/KMLightMember/Controller/ComparativeTable/View/KMComparativeTableView.xib

@@ -20,7 +20,7 @@
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
-        <customView misplaced="YES" id="c22-O7-iKe">
+        <customView id="c22-O7-iKe">
             <rect key="frame" x="0.0" y="0.0" width="836" height="659"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>

+ 2 - 1
PDF Office/PDF Master/Class/KMLightMember/Controller/ComparativeTable/View/KMComparativeView/KMComparativeView.swift

@@ -54,7 +54,8 @@ class KMComparativeView: KMBaseXibView {
             "type": 1,
             "title": "Subscription Member",
             "subtitle": "$39.99",
-            "describe": "$79.99 billed year, anytime unsubscribe",
+            "describe": "billed year, anytime unsubscribe",
+            "productId": PRODUCT_1,
             "content": [
                 ["title": "Support efficient batch operation function",
                  "state": true],

+ 30 - 8
PDF Office/PDF Master/Class/KMLightMember/Controller/ComparativeTable/View/KMComparativeView/View/KMComparativeViewCollectionItem.swift

@@ -6,6 +6,7 @@
 //
 
 import Cocoa
+import StoreKit
 
 typealias KMComparativeViewCollectionItemDoneAction = (_ view: KMComparativeViewCollectionItem, _ data: [String: Any]) -> Void
 class KMComparativeViewCollectionItem: NSCollectionViewItem {
@@ -66,7 +67,8 @@ class KMComparativeViewCollectionItem: NSCollectionViewItem {
             self.titleLabel.stringValue = NSLocalizedString(data["title"] as! String, comment: "")
             self.subtitleLabel.stringValue = NSLocalizedString(data["subtitle"] as! String, comment: "")
             self.doneButton.title = NSLocalizedString(data["buttonTitle"] as! String, comment: "")
-            self.describeLabel.stringValue = NSLocalizedString(data["describe"] as? String ?? "", comment: "")
+            let describe = NSLocalizedString(data["describe"] as? String ?? "", comment: "")
+            self.describeLabel.stringValue = describe
             
             if data["type"] as! Int == 1 {
                 self.describeLabel.isHidden = false
@@ -76,6 +78,33 @@ class KMComparativeViewCollectionItem: NSCollectionViewItem {
                 self.doneButton.border(NSColor(hex: "#FF852E"), 0, 20)
                 self.doneButton.contentTintColor = NSColor(hex: "#FFFFFF")
                 self.doneButton.font = NSFont.SFProTextSemibold(16)
+                
+                if KMLightMemberManager.manager.purchaseState == .trialExpired ||
+                    KMLightMemberManager.manager.purchaseState == .subscriptionExpired {
+                    self.iconImageView.isHidden = true
+                } else {
+                    self.iconImageView.isHidden = false
+                }
+                
+                if KMInAppPurchaseManager.manager.availableProducts.count == 0 {
+                    KMInAppPurchaseManager.manager.fetchProducts { [unowned self] isSuccess, products, error in
+                        let productId: String = data["productId"] as! String
+                        for product in KMInAppPurchaseManager.manager.availableProducts {
+                            if product.productIdentifier == productId {
+                                print("-----------------------------")
+                                print(product.priceLocale.currencyCode)
+                                print(product.introductoryPrice?.price)
+                                print(product.price)
+                                print("-----------------------------")
+                                let currencyCode: String = product.priceLocale.currencyCode ?? "$"
+                                let price: String = product.introductoryPrice?.price.description ?? "39.9"
+                                let originPrice: String = product.price.description ?? "79.9"
+                                self.subtitleLabel.stringValue = "\(currencyCode) \(price)"
+                                self.describeLabel.stringValue = "\(currencyCode) \(originPrice) \(describe)"
+                            }
+                        }
+                    }
+                }
             } else {
                 self.describeLabel.isHidden = true
                 self.iconImageView.isHidden = true
@@ -87,13 +116,6 @@ class KMComparativeViewCollectionItem: NSCollectionViewItem {
             }
             self.contentCollectionView.reloadData()
         }
-        
-        if KMLightMemberManager.manager.purchaseState == .trialExpired ||
-            KMLightMemberManager.manager.purchaseState == .subscriptionExpired {
-            self.iconImageView.isHidden = true
-        } else {
-            self.iconImageView.isHidden = false
-        }
     }
 }
 

+ 19 - 0
PDF Office/PDF Master/Class/KMLightMember/Controller/SubscriptionView/WaterMark/View/KMSubscribeWaterMarkView.swift

@@ -110,6 +110,25 @@ class KMSubscribeWaterMarkView: KMBaseXibView {
         self.lineView.isHidden = false
         self.restoreButton.isHidden = false
         self.textView.isHidden = false
+        
+        if KMInAppPurchaseManager.manager.availableProducts.count == 0 {
+            KMInAppPurchaseManager.manager.fetchProducts { [unowned self] isSuccess, products, error in
+                let productId: String = PRODUCT_1
+                for product in KMInAppPurchaseManager.manager.availableProducts {
+                    if product.productIdentifier == productId {
+                        print("-----------------------------")
+                        print(product.priceLocale.currencyCode)
+                        print(product.introductoryPrice?.price)
+                        print(product.price)
+                        print("-----------------------------")
+                        let currencyCode: String = product.priceLocale.currencyCode ?? "$"
+                        let price: String = product.introductoryPrice?.price.description ?? "39.9"
+                        let originPrice: String = product.price.description ?? "79.9"
+                        self.subscribeButton.title = "\(currencyCode) \(price) / year"
+                    }
+                }
+            }
+        }
 #endif
 
 #if VERSION_DMG

+ 21 - 21
PDF Office/PDF Master/Class/KMLightMember/Manager/KMRequestServerManager.swift

@@ -605,34 +605,34 @@ extension KMRequestServerManager {
         }
         
         if code == 330 {
-            if KMLoginWindowController.fetchSampleController() == nil {
-                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.2, execute: { [unowned self] in
-                    if loginAlert == nil {
-                        loginAlert = NSAlert()
-                        loginAlert?.messageText = NSLocalizedString("请重新登录", comment: "")
-                        loginAlert?.informativeText = NSLocalizedString("您的账号已在其他设备登录,若非本人操作,请尽快修改您的账号密码", comment: "")
-                        loginAlert?.addButton(withTitle: NSLocalizedString("登录", comment: ""))
-                        loginAlert?.addButton(withTitle: NSLocalizedString("取消", comment: ""))
-                        var window = NSApp.mainWindow
-                        if NSApp.mainWindow?.sheets.first != nil {
-                            window = NSApp.mainWindow?.sheets.first
-                        }
-                        if window != nil {
-                            loginAlert?.beginSheetModal(for: window!) { result in
-                                if (result == .alertFirstButtonReturn) {
+            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.2, execute: { [unowned self] in
+                if loginAlert == nil {
+                    loginAlert = NSAlert()
+                    loginAlert?.messageText = NSLocalizedString("请重新登录", comment: "")
+                    loginAlert?.informativeText = NSLocalizedString("您的账号已在其他设备登录,若非本人操作,请尽快修改您的账号密码", comment: "")
+                    loginAlert?.addButton(withTitle: NSLocalizedString("登录", comment: ""))
+                    loginAlert?.addButton(withTitle: NSLocalizedString("取消", comment: ""))
+                    var window = NSApp.mainWindow
+                    if NSApp.mainWindow?.sheets.first != nil {
+                        window = NSApp.mainWindow?.sheets.first
+                    }
+                    if window != nil {
+                        loginAlert?.beginSheetModal(for: window!) { result in
+                            if (result == .alertFirstButtonReturn) {
+                                if KMLoginWindowController.fetchSampleController() == nil {
                                     KMLoginWindowController.show(window: window!)
-                                } else if result == .alertSecondButtonReturn {
-                                    self.loginAlert = nil
-                                    return
                                 }
+                            } else if result == .alertSecondButtonReturn {
                                 self.loginAlert = nil
+                                return
                             }
-                        } else {
                             self.loginAlert = nil
                         }
+                    } else {
+                        self.loginAlert = nil
                     }
-                })
-            }
+                }
+            })
         }
         
 //        if code == 500 {