Browse Source

【综合】Win Back 串接

tangchao 2 months ago
parent
commit
e005259af9

+ 1 - 1
PDF Office/PDF Master/AppDelegate.swift

@@ -120,7 +120,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, iRateDelegate {
             
         }
         if #available(macOS 12.0, *) {
-            TransactionObserver()
+            _ = TransactionObserver.shared
         } else {
             // Fallback on earlier versions
         };

+ 6 - 0
PDF Office/PDF Master/Class/Account/WinBack/Window/KMWinBackWindowController.swift

@@ -17,6 +17,12 @@ import SwiftUI
 @objcMembers class KMIAPTransaction: NSObject {
     var transactionIdentifier: String?
     var productIdentifier: String?
+    
+    override init() {
+        super.init()
+        self.transactionIdentifier = ""
+        self.productIdentifier = ""
+    }
 }
 
 let KMWinBackIAPProductPurchasedNotificationName = "KMWinBackIAPProductPurchasedNotification"

+ 7 - 3
PDF Office/PDF Master/Class/Purchase/IAPProductsManager.m

@@ -1142,8 +1142,12 @@ NSString * const KMMemberInfoChangeNotification = @"KMMemberInfoChangeNotificati
         self.proAIProduct.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.fourDevicesAllAccessPackNew6Months_lite.productIdentifier]) {
         [self loadReceipt:^(NSError *error) {
-            [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
-                                                                object:transaction];
+//            [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification
+//                                                                object:nil, ];
+            NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
+            dict[@"tid"] = transactionId ? transactionId : @"";
+            dict[@"pid"] = productId ? productId : @"";
+            [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPSubscriptionLoadedNotification object:nil userInfo:dict];
         }];
         self.fourDevicesAllAccessPackNew6Months_lite.isSubscribed = YES;
     } else if ([productIdentifier isEqualToString:self.fourDevicesAllAccessPackNew12months_lite.productIdentifier]) {
@@ -1222,7 +1226,7 @@ NSString * const KMMemberInfoChangeNotification = @"KMMemberInfoChangeNotificati
         }];
     }
     if (!self.isPurchasing) {
-        return;
+//        return;
     }
     dispatch_async(dispatch_get_main_queue(), ^{
         [[NSNotificationCenter defaultCenter] postNotificationName:KMIAPProductPurchasedNotification

+ 2 - 0
PDF Office/PDF Master/Class/Purchase/TransactionObserver.swift

@@ -17,6 +17,8 @@ import StoreKit
     
 //    @Environment(\.displayStoreKitMessage) private var displayStoreMessage
     
+    static let shared = TransactionObserver()
+    
     override init() {
         super.init()
         updates = newTransactionListenerTask()

+ 3 - 0
PDF Office/PDF Master/MemberCenter/ViewModel/KMProductModel.swift

@@ -1341,6 +1341,9 @@ class KMProductModel: ObservableObject {
         } else if let userInfo = notification.object as? KMIAPTransaction {
             transactionId = userInfo.transactionIdentifier ?? ""
             productId = userInfo.productIdentifier ?? ""
+        } else if let info = notification.userInfo as? [String : Any] {
+            transactionId = info["tid"] as? String ?? ""
+            productId = info["pid"] as? String ?? ""
         }
         
         if transactionId.isEmpty == false && productId.isEmpty == false {