Просмотр исходного кода

3.6.28(4)对错误类型做一些处理

100Years 1 неделя назад
Родитель
Сommit
754e06ab6b

+ 2 - 2
AIEmoji.xcodeproj/project.pbxproj

@@ -3276,7 +3276,7 @@
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 3;
+				CURRENT_PROJECT_VERSION = 4;
 				DEVELOPMENT_TEAM = 65UD255J84;
 				ENABLE_USER_SCRIPT_SANDBOXING = NO;
 				GENERATE_INFOPLIST_FILE = YES;
@@ -3315,7 +3315,7 @@
 				ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
 				CLANG_ENABLE_MODULES = YES;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 3;
+				CURRENT_PROJECT_VERSION = 4;
 				DEVELOPMENT_TEAM = 65UD255J84;
 				ENABLE_USER_SCRIPT_SANDBOXING = NO;
 				GENERATE_INFOPLIST_FILE = YES;

+ 4 - 2
AIEmoji/Business/TSPurchaseMembershipVC/TSPurchaseVideoTimesVC/TSPurchaseVideoTimesVC.swift

@@ -149,6 +149,7 @@ extension TSPurchaseVideoTimesVC {
                 case .paying:
                     TSToastShared.showLoading(text: "Purchasing now".localized,containerView: self.view)
                 case .paySuccess:
+                    dePrint("购买成功了视频次数")
                     TSToastShared.hideLoading()
                     var loadingText = "Video Effects Pack Activated!".localized
                     if let purchaseNum = self.viewModel.selectedType.purchaseNum {
@@ -156,7 +157,7 @@ extension TSPurchaseVideoTimesVC {
                     }
                     debugPrint(loadingText)
                     TSToastShared.showToast(text:loadingText)
-                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
                         self.closePage()
                     }
 
@@ -175,8 +176,9 @@ extension TSPurchaseVideoTimesVC {
                         loadingText = String(format: "Congratulations on your purchase! You have %d video effect uses. Try now!".localized, purchaseNum)
                     }
                     debugPrint(loadingText)
+                    
                     TSToastShared.showToast(text:loadingText)
-                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
                         self.closePage()
                     }
                     

+ 49 - 10
AIEmoji/Common/Purchase/TSPurchaseManager.swift

@@ -75,11 +75,11 @@ public class PurchaseManager: NSObject {
 
         initializeForFree()
         
-#if DEBUG
-    verifyPayResult(transaction: SKPaymentTransaction(), useSandBox: true)
-#else
-    verifyPayResult(transaction: SKPaymentTransaction(), useSandBox: false)
-#endif
+//#if DEBUG
+//    verifyPayResult(transaction: SKPaymentTransaction(), useSandBox: true)
+//#else
+//    verifyPayResult(transaction: SKPaymentTransaction(), useSandBox: false)
+//#endif
         
     }
     
@@ -400,8 +400,10 @@ extension PurchaseManager: SKPaymentTransactionObserver {
             case .failed:
 
                 SKPaymentQueue.default().finishTransaction(transaction)
-                
-                if let error = transaction.error as NSError? {
+        
+                //非购买次数类(就是订阅续费类)报错处理
+                if self.purchaseNumProducts.contains(transaction.payment.productIdentifier) == false,
+                    let error = transaction.error as NSError? {
                     // 1. 检查内层错误
                     if let underlyingError = error.userInfo[NSUnderlyingErrorKey] as? NSError {
                         if underlyingError.domain == "ASDServerErrorDomain" && underlyingError.code == 3532 {
@@ -422,11 +424,21 @@ extension PurchaseManager: SKPaymentTransactionObserver {
                 }
                 
                 // Transaction was cancelled or failed before being added to the server queue.
+//                var message = "Payment Failed"
+//                if let error = transaction.error as? SKError,
+//                   error.code == SKError.paymentCancelled {
+//                    message = "The subscription was canceled"
+//                }
+                
                 var message = "Payment Failed"
-                if let error = transaction.error as? SKError,
-                   error.code == SKError.paymentCancelled {
-                    message = "The subscription was canceled"
+                if let error = transaction.error as? SKError{
+                    if error.code == SKError.paymentCancelled {
+                        message = "The subscription was canceled"
+                    }else{
+                        message = error.localizedDescription
+                    }
                 }
+       
                 purchase(self, didChaged: .payFail, object: message)
                 subscriptionApple(type: .result, jsonString: message)
             case .restored:
@@ -728,4 +740,31 @@ extension PurchaseManager {
  当用户决定购买某个产品后,根据产品信息(SKProduct对象)创建SKPayment对象,然后使用SKPaymentQueue的add(_:)方法将支付请求添加到支付队列。
  同时,在应用启动等合适的时机,通过SKPaymentQueue的addTransactionObserver(_:)方法添加交易观察者。当支付状态发生变化时,paymentQueue(_:updatedTransactions:)方法会被调用,在这里可以根据交易状态(如购买成功、失败、恢复等)进行相应的处理。
 
+ 
+ func handleSKError(_ error: SKError) {
+     switch error.code {
+     case .paymentCancelled:
+         print("用户取消支付")
+     case .paymentNotAllowed:
+         print("设备不允许支付(如未登录 Apple ID)")
+     case .paymentInvalid:
+         print("商品 ID 无效或未配置")
+     case .storeProductNotAvailable:
+         print("商品在当前地区不可用")
+     default:
+         print("其他错误: \(error.localizedDescription)")
+     }
+     
+     // 获取详细的错误信息
+     print("错误域: \(error.errorDomain)")
+     print("错误码: \(error.errorCode)")
+     print("本地化描述: \(error.localizedDescription)")
+     print("失败原因: \(error.localizedFailureReason ?? "")")
+ }
+ if let userInfo = (error as NSError).userInfo {
+     print("完整错误信息: \(userInfo)")
+     // 示例输出:
+     // ["NSLocalizedDescription": "此设备不允许应用内购买",
+     //  "NSLocalizedFailureReason": "未登录 Apple ID"]
+ }
  */