Pārlūkot izejas kodu

【fix】【卡片】App Store免费版-免费试用中- Apple取消续订试用,重启app不会弹出退订提示弹窗

tangchao 2 mēneši atpakaļ
vecāks
revīzija
f68af5b20e

+ 8 - 2
PDF Office/PDF Master/Class/Purchase/IAPReceiptModel.h

@@ -130,11 +130,14 @@ NS_ASSUME_NONNULL_BEGIN
 
 @interface IAPReceiptTool: NSObject
 
+// 是否在免费试用中
++ (BOOL)isFreeTrailingWithModel:(IAPReceiptModel *)model withProductId:(NSString *)productId;
+
 // 是否为新用户 
 + (BOOL)isNewUserWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier;
 
 // 是否有享受过 推介优惠 [免费试用]
-+ (BOOL)hasTrialWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier;
++ (BOOL)hasFreeTrialWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier;
 
 // 是否有享受过 推介优惠
 + (BOOL)hasIntroOfferWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier;
@@ -142,8 +145,11 @@ NS_ASSUME_NONNULL_BEGIN
 // 获取订阅群组的所有票据
 + (NSArray <IAPReceiptInfoModel *> *)fetchReceiptsWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier;
 
+// 获取对应商品的最后的票据
++ (IAPReceiptInfoModel *)fetchProductLastestReceiptsWithModel:(IAPReceiptModel *)model withProductId:(NSString *)productId;
+
 // 获取对应商品的所有票据
-+ (NSArray <IAPReceiptInfoModel *> *)fetchProductReceiptsWithModel:(IAPReceiptModel *)model withProductCode:(NSString *)productCode;
++ (NSArray <IAPReceiptInfoModel *> *)fetchProductReceiptsWithModel:(IAPReceiptModel *)model withProductId:(NSString *)productId;
 
 // 获取所有的票据
 + (NSArray <IAPReceiptInfoModel *> *)fetchReceiptsWithModel:(IAPReceiptModel *)model;

+ 31 - 4
PDF Office/PDF Master/Class/Purchase/IAPReceiptModel.m

@@ -135,8 +135,22 @@
 
 @implementation IAPReceiptTool
 
++ (BOOL)isFreeTrailingWithModel:(IAPReceiptModel *)model withProductId:(NSString *)productId {
+    IAPReceiptInfoModel *lastestM = [self fetchProductLastestReceiptsWithModel:model withProductId:productId];
+    if (lastestM == nil) {
+        return false;
+    }
+    if (lastestM.is_trial_period == false) {
+        return false;
+    }
+    long long expiresDate = [lastestM.expires_date_ms longLongValue]/1000;
+    long long currentDate = [[NSDate date] timeIntervalSince1970];
+    BOOL isActive = (expiresDate > currentDate) ? YES : NO;
+    return isActive;
+}
+
 + (BOOL)isNewUserWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier {
-    if ([self hasTrialWithModel:model withGroupIdentifier:groupIdentifier]) {
+    if ([self hasFreeTrialWithModel:model withGroupIdentifier:groupIdentifier]) {
         return false;
     }
     if ([self hasIntroOfferWithModel:model withGroupIdentifier:groupIdentifier]) {
@@ -145,7 +159,7 @@
     return true;
 }
 
-+ (BOOL)hasTrialWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier {
++ (BOOL)hasFreeTrialWithModel:(IAPReceiptModel *)model withGroupIdentifier:(NSString *)groupIdentifier {
     for (IAPReceiptInfoModel *m in [self fetchReceiptsWithModel:model withGroupIdentifier:groupIdentifier]) {
         if (m.is_trial_period) {
             return true;
@@ -174,10 +188,23 @@
     return [results copy];
 }
 
-+ (NSArray<IAPReceiptInfoModel *> *)fetchProductReceiptsWithModel:(IAPReceiptModel *)model withProductCode:(NSString *)productCode {
++ (IAPReceiptInfoModel *)fetchProductLastestReceiptsWithModel:(IAPReceiptModel *)model withProductId:(NSString *)productId {
+    IAPReceiptInfoModel *flagM= nil;
+    long long lastestExpiresDate = 0;
+    for (IAPReceiptInfoModel *m in [self fetchProductReceiptsWithModel:model withProductId:productId]) {
+        long long theExpiresDate = [m.expires_date_ms longLongValue]/1000;
+        if (theExpiresDate > lastestExpiresDate) {
+            lastestExpiresDate = theExpiresDate;
+            flagM = m;
+        }
+    }
+    return flagM;
+}
+
++ (NSArray<IAPReceiptInfoModel *> *)fetchProductReceiptsWithModel:(IAPReceiptModel *)model withProductId:(nonnull NSString *)productId {
     NSMutableArray *results = [NSMutableArray arrayWithCapacity:4];
     for (IAPReceiptInfoModel *m in [self fetchReceiptsWithModel:model]) {
-        if ([m.product_id isEqualToString:productCode] == false) {
+        if ([m.product_id isEqualToString:productId] == false) {
             continue;
         }
         [results addObject:m];

+ 6 - 1
PDF Office/PDF Master/MemberCenter/ViewModel/KMProductModel.swift

@@ -1347,7 +1347,12 @@ class KMProductModel: ObservableObject {
                     isSubscribed = true
                 }
             } else if productId == "com.pdfreaderpro.mac_free.member.all_access_pack_advanced_annual.001" {
-                productCode = "advanced-annual-subscription"
+                let model = IAPReceiptTool.fetchProductLastestReceipts(with: IAPProductsManager.default().receiptModel, withProductId: productId)
+                if model.is_trial_period {
+                    productCode = "advanced-annual-subscription-trail"
+                } else {
+                    productCode = "advanced-annual-subscription"
+                }
                 if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isSubscribed {
                     isSubscribed = true
                 }

+ 18 - 0
PDF Office/PDF Master/MemberCenter/WindowsController/KMProductCompareWC.swift

@@ -1858,6 +1858,24 @@ class KMProductCompareWC: NSWindowController {
                 return
             }
 //            addWaitingView(to: window?.contentView ?? NSView())
+            if discountType == .advancedYearSubscribeTrialingCancel {
+                if product == IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite ||
+                    product == IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite {
+                    if KMMemberInfo.shared.isLogin == false {
+                        let result = IAPReceiptTool.isFreeTrailing(with: IAPProductsManager.default().receiptModel, withProductId: (product?.product?.productIdentifier)!)
+                        if result {
+//                            return
+                        }
+                    } else {
+                        let member = KMMemberInfo.shared
+                        if member.is_advanced_year_subscribe() && member.is_trailing() {
+//                            showAlert(message: NSLocalizedString("kkkkkkk", comment: ""))
+//                            return
+                        }
+                    }
+                }
+            }
+            
             model.appstorePurchaseAction(sender.tag, discountType: discountType_) { [weak self] success, msg in
                 guard let self = self else { return }
             }