|
|
@@ -96,13 +96,18 @@ extension QSLVipManager {
|
|
|
self.isCheck = false
|
|
|
|
|
|
print("开始恢复订阅")
|
|
|
- QSLVipManager.shared.checkTransAction {isSuccess, response in
|
|
|
- if(isSuccess){
|
|
|
- self.restoreOrder()
|
|
|
- }else{
|
|
|
- self.isRestoring = false
|
|
|
- self.restoreCompleteClosure?(false)
|
|
|
+
|
|
|
+ if #available(iOS 15.0, *) {
|
|
|
+ QSLVipManager.shared.checkHistoryAction {isSuccess, response in
|
|
|
+ if(isSuccess){
|
|
|
+ self.restoreOrder()
|
|
|
+ }else{
|
|
|
+ self.isRestoring = false
|
|
|
+ self.restoreCompleteClosure?(false)
|
|
|
+ }
|
|
|
}
|
|
|
+ }else{
|
|
|
+ self.restoreOrder()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -125,7 +130,8 @@ extension QSLVipManager {
|
|
|
|
|
|
}
|
|
|
|
|
|
- func checkTransAction(complete1: ((Bool, [String:Any]) -> Void)?) {
|
|
|
+ @available(iOS 15.0, tvOS 15.0, *)
|
|
|
+ func checkHistoryAction(complete1: ((Bool, [String:Any]) -> Void)?) {
|
|
|
|
|
|
if #available(iOS 13.0, *) {
|
|
|
Task{
|
|
|
@@ -150,8 +156,6 @@ extension QSLVipManager {
|
|
|
|
|
|
// 检查这个未完成的交易是否是降级交易
|
|
|
if let product = try? await Product.products(for: [transaction.productID]).first {
|
|
|
- print("发现未完成的订阅交易: \(transaction.productID)")
|
|
|
-
|
|
|
|
|
|
// 如果未完成的交易购买时间比当前有效订阅晚,很可能是降级
|
|
|
let purchaseDate = transaction.purchaseDate
|
|
|
@@ -170,7 +174,6 @@ extension QSLVipManager {
|
|
|
if purchaseDate > currentTransaction.purchaseDate
|
|
|
&& transaction.productID != currentTransaction.productID
|
|
|
{
|
|
|
- print("检测到降级订阅: \(transaction.productID)")
|
|
|
pendingDowngradeProductID = transaction.productID
|
|
|
break
|
|
|
}
|
|
|
@@ -201,8 +204,6 @@ extension QSLVipManager {
|
|
|
|
|
|
// 添加到所有有效商品ID列表
|
|
|
allActiveProductIDs.append(transaction.productID)
|
|
|
- print("发现有效订阅: \(transaction.productID)")
|
|
|
-
|
|
|
|
|
|
// 获取订阅组 ID 和产品信息
|
|
|
guard let product = try? await Product.products(for: [transaction.productID]).first,
|
|
|
@@ -224,9 +225,6 @@ extension QSLVipManager {
|
|
|
let autoRenewProductID = renewalInfo.autoRenewPreference,
|
|
|
autoRenewProductID != transaction.productID
|
|
|
{
|
|
|
- // 发现pending的产品变更,通常是降级
|
|
|
- print(
|
|
|
- "通过renewalInfo检测到pending的订阅变更: \(autoRenewProductID)")
|
|
|
pendingDowngradeProductID = autoRenewProductID
|
|
|
}
|
|
|
default:
|
|
|
@@ -249,11 +247,6 @@ extension QSLVipManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- print("所有有效订阅商品ID: \(allActiveProductIDs)")
|
|
|
- print("按订阅组分组的订阅数量: \(activeTransactions.count)")
|
|
|
-
|
|
|
-
|
|
|
// 优先使用通过未完成交易或renewalInfo找到的降级商品ID
|
|
|
if let pendingProductID = pendingDowngradeProductID {
|
|
|
inSubscribeAppleGoodId = pendingProductID
|
|
|
@@ -261,13 +254,10 @@ extension QSLVipManager {
|
|
|
if let transaction = activeTransactions.values.first {
|
|
|
inSubscribeAppAccountToken = transaction.appAccountToken?.uuidString ?? ""
|
|
|
}
|
|
|
- print("使用降级订阅商品ID: \(pendingProductID)")
|
|
|
} else if let transaction = activeTransactions.values.first {
|
|
|
// 如果有多个订阅组,这里可能需要根据业务逻辑选择合适的订阅
|
|
|
inSubscribeAppleGoodId = transaction.productID
|
|
|
inSubscribeAppAccountToken = transaction.appAccountToken?.uuidString ?? ""
|
|
|
- print("当前使用的订阅商品ID: \(transaction.productID)")
|
|
|
-
|
|
|
|
|
|
// 如果有多个订阅,打印警告
|
|
|
if activeTransactions.count > 1 {
|
|
|
@@ -284,8 +274,6 @@ extension QSLVipManager {
|
|
|
}else{
|
|
|
complete1?(true, ["appleGoodsId":inSubscribeAppleGoodId,"appAccountToken":inSubscribeAppAccountToken])
|
|
|
}
|
|
|
- print("inSubscribeAppleGoodId:\(inSubscribeAppleGoodId)")
|
|
|
- print("inSubscribeAppAccountToken:\(inSubscribeAppAccountToken)")
|
|
|
|
|
|
}
|
|
|
}else{
|