0

我正在使用SwiftyStoreKit并弄清楚如何检索收据验证的状态。我想statusreceiptInvalid(receipt: ["status": 21004, "environment": Sandbox], status: SwiftyStoreKit.ReceiptStatus.secretNotMatching). 我将如何获得价值21004

receiptInvalid是最后一种情况的结果:

public enum ReceiptError: Swift.Error {
// No receipt data
case noReceiptData
// No data received
case noRemoteData
// Error when encoding HTTP body into JSON
case requestBodyEncodeError(error: Swift.Error)
// Error when proceeding request
case networkError(error: Swift.Error)
// Error when decoding response
case jsonDecodeError(string: String?)
// Receive invalid - bad status returned
case receiptInvalid(receipt: ReceiptInfo, status: ReceiptStatus)
}

收据信息:

public typealias ReceiptInfo = [String: AnyObject]

最终目标是为 Apple App Review 测试代码21007。谢谢!

编辑:注释所在的位置是什么代码?

case .error(let error):
            print("Receipt verification failed: \(error)")
            //error prints receiptInvalid(receipt: ["status": 21004, "environment": Sandbox], status: SwiftyStoreKit.ReceiptStatus.secretNotMatching)
            if case .receiptInvalid = error {
                //What goes here?
            }
4

1 回答 1

1

您可以使用方便的计算变量扩展枚举以访问关联值:

 extension ReceiptError {
   var invalidReceipt: (receipt: ReceiptInfo, status: RecriptStatus)? {
       switch self {
       case .receiptInvalid(let receipt, let status):
           return (receipt: receipt, status: status)
       default:
           return nil
       }
   }
}

print(someReceiptError.invalidReceipt.receipt["status"
于 2018-12-19T23:59:30.027 回答