首页 > 解决方案 > 尝试进行收据验证时出现 ASDServerErrorDomain 错误

问题描述

我在应用商店中使用以下代码进行收据验证。如果收据不存在,则要求用户登录。这是我使用的类。

收据提取器

import Foundation
import StoreKit

class ReceiptFetcher : NSObject {
    
    public var receiptRefreshRequest = SKReceiptRefreshRequest()
    
    override init() {
        super.init()
       // receiptRefreshRequest.delegate = self
    }
    
    func fetchReceipt() {
       
        let receiptPath = Bundle.main.appStoreReceiptURL?.path
     
        
        do {
             receiptRefreshRequest.start()
        }
        catch {
            print("Could not check for receipt presence for some reason... \(error.localizedDescription)")
            
        }
  
}
}

检查收据是否存在以及是否不尝试获取收据。对于当前场景,没有收据,调试器会命中 fetchreceipt 块。

 if !FileManager.default.fileExists(atPath: receiptPath!){
        receiptFetcher.receiptRefreshRequest.delegate=self
        receiptFetcher.fetchReceipt();
        }
        else
        {
            receiptValidation()
        }

func request(_ request: SKRequest, didFailWithError error: Error) {
        
         print("Something went wrong: \(error.localizedDescription)")
        DispatchQueue.main.async {
            if let presenter = self.presenting as? ViewController {
                                  presenter.showreceipterror()
                                  self.dismissViewController(self)
                                  NSApplication.shared.terminate(self)                                    
                              }
        }

这会导致以下错误。沙盒功能在允许传出连接的情况下打开。之前我能够成功以沙盒用户身份登录,我认为问题是在我从应用商店连接中删除用户后开始的。我已经清除了现有的收据通过重新构建。

   0x600001c59ae0>: Finished refreshing receipt with error: Error Domain=ASDServerErrorDomain Code=500317 "Unhandled exception" UserInfo={NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}

标签: swiftmacosapp-store-connectreceipt-validation

解决方案


推荐阅读