From 0c3ccc278a410b39db7064ba24a60d684a401a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6ttger?= Date: Sat, 1 Mar 2025 18:56:18 +0100 Subject: [PATCH] Fix restore --- NearDrop/AppDelegate.swift | 17 +---------------- NearDrop/IAP/GetPlusView.swift | 5 ++++- NearDrop/IAP/PurchaseHelper.swift | 22 +++++++++++++--------- QuickDrop.xcodeproj/project.pbxproj | 4 ++-- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/NearDrop/AppDelegate.swift b/NearDrop/AppDelegate.swift index 92b2215..8b2ccdd 100644 --- a/NearDrop/AppDelegate.swift +++ b/NearDrop/AppDelegate.swift @@ -273,23 +273,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, MainAppDelegate{ } } + struct TransferInfo { let device: RemoteDeviceInfo let transfer: TransferMetadata } - -class WindowDelegate: NSObject, NSWindowDelegate { - - let willClose: () -> Void - - init(willClose: @escaping () -> Void) { - self.willClose = willClose - } - - - func windowWillClose(_ notification: Notification) { - print("Window closed!") - // Perform any cleanup or state updates here - willClose() - } -} diff --git a/NearDrop/IAP/GetPlusView.swift b/NearDrop/IAP/GetPlusView.swift index 348e727..ac1e6fe 100644 --- a/NearDrop/IAP/GetPlusView.swift +++ b/NearDrop/IAP/GetPlusView.swift @@ -105,16 +105,19 @@ struct GetPlusView: View { switch result { case .success(let success): if success { + log("[LUI] Restored purchases successfully") withAnimation { isPlusVersion = true } boughtSuccessAlert = true } else { + log("[LUI] Nothing to restore") //nothing to restore - restoreFailed(message: "plusview_nothingtorestore") + restoreFailed(message: "plusview_nothingtorestore".localized()) } case .failure(let error): + log("[LUI] Error restoring purchases: \(error.localizedDescription)") log(error.localizedDescription) restoreFailed(message: error.localizedDescription) } diff --git a/NearDrop/IAP/PurchaseHelper.swift b/NearDrop/IAP/PurchaseHelper.swift index 125f259..f43d36d 100644 --- a/NearDrop/IAP/PurchaseHelper.swift +++ b/NearDrop/IAP/PurchaseHelper.swift @@ -88,14 +88,19 @@ class IAPManager: NSObject, ObservableObject { extension IAPManager: SKPaymentTransactionObserver { func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { + + log("IAP updatedTransactions") + transactions.forEach { (transaction) in - + switch transaction.transactionState { case .purchased: + log("IAP purchased") onBuyProductHandler?(.success(true)) SKPaymentQueue.default().finishTransaction(transaction) case .restored: + log("IAP restored") totalRestoredPurchases += 1 onBuyProductHandler?(.success(true)) SKPaymentQueue.default().finishTransaction(transaction) @@ -120,17 +125,16 @@ extension IAPManager: SKPaymentTransactionObserver { } - func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) { - if totalRestoredPurchases != 0 { - onBuyProductHandler?(.success(true)) - } else { - log("[LUI] IAP: No purchases to restore!") - onBuyProductHandler?(.success(false)) + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + if self.totalRestoredPurchases == 0 { + log("[LUI] IAP: No purchases to restore!") + self.onBuyProductHandler?(.success(false)) + } } } - - + + func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) { if let error = error as? SKError { if error.code != .paymentCancelled { diff --git a/QuickDrop.xcodeproj/project.pbxproj b/QuickDrop.xcodeproj/project.pbxproj index 5ada8a5..b43d455 100644 --- a/QuickDrop.xcodeproj/project.pbxproj +++ b/QuickDrop.xcodeproj/project.pbxproj @@ -786,7 +786,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SHARED_BUILD = 7; - SHARED_VERSION = 1.2; + SHARED_VERSION = 1.2.1; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; @@ -845,7 +845,7 @@ MTL_FAST_MATH = YES; SDKROOT = macosx; SHARED_BUILD = 7; - SHARED_VERSION = 1.2; + SHARED_VERSION = 1.2.1; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; };