|
@@ -307,10 +307,33 @@ extension PurchaseManager: SKPaymentTransactionObserver {
|
|
|
|
|
|
SKPaymentQueue.default().finishTransaction(transaction)
|
|
|
// Transaction was cancelled or failed before being added to the server queue.
|
|
|
+
|
|
|
+
|
|
|
+ if let error = transaction.error as NSError? {
|
|
|
+ // 1. 检查内层错误
|
|
|
+ if let underlyingError = error.userInfo[NSUnderlyingErrorKey] as? NSError {
|
|
|
+ if underlyingError.domain == "ASDServerErrorDomain" && underlyingError.code == 3532 {
|
|
|
+ print("用户已订阅,禁止重复购买")
|
|
|
+ restorePremium()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 2. 检查外层 SKError
|
|
|
+ else if error.domain == SKErrorDomain {
|
|
|
+ switch SKError.Code(rawValue: error.code) {
|
|
|
+ case .unknown:
|
|
|
+ print("未知错误,可能是服务器问题")
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
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"
|
|
|
+ }
|
|
|
}
|
|
|
purchase(self, didChaged: .payFail, object: message)
|
|
|
|