From 2620bd684517def276b350a9861ee7838cfa06ee Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Mon, 15 Dec 2025 15:22:27 +0800 Subject: [PATCH] 1 --- keyBoard/Class/Pay/M/IAPVerifyTransactionObj.h | 3 ++- keyBoard/Class/Pay/M/IAPVerifyTransactionObj.m | 7 +++++-- keyBoard/Class/Pay/VC/KBJfPay.m | 13 +++++++++++++ keyBoard/Class/Shop/VC/KBShopVC.m | 5 +++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/keyBoard/Class/Pay/M/IAPVerifyTransactionObj.h b/keyBoard/Class/Pay/M/IAPVerifyTransactionObj.h index 0fa4327..3ec8cae 100644 --- a/keyBoard/Class/Pay/M/IAPVerifyTransactionObj.h +++ b/keyBoard/Class/Pay/M/IAPVerifyTransactionObj.h @@ -9,9 +9,10 @@ NS_ASSUME_NONNULL_BEGIN +FOUNDATION_EXPORT NSString * const KBIAPDidCompletePurchaseNotification; + @interface IAPVerifyTransactionObj : NSObject @end NS_ASSUME_NONNULL_END - diff --git a/keyBoard/Class/Pay/M/IAPVerifyTransactionObj.m b/keyBoard/Class/Pay/M/IAPVerifyTransactionObj.m index 8126ded..99f2da3 100644 --- a/keyBoard/Class/Pay/M/IAPVerifyTransactionObj.m +++ b/keyBoard/Class/Pay/M/IAPVerifyTransactionObj.m @@ -8,6 +8,8 @@ #import "KBHUD.h" //#import "KBLoginSheetViewController.h" #import "KBBizCode.h" + +NSString * const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurchaseNotification"; @interface IAPVerifyTransactionObj () @property (nonatomic, strong) PayVM *payVM; @end @@ -41,10 +43,11 @@ __weak typeof(self) weakSelf = self; [self.payVM applePayReqWithParams:params needShow:NO completion:^(NSInteger sta, NSString * _Nullable msg) { // [KBHUD dismiss]; - [KBHUD showInfo:(sta == !KBBizCodeSuccess ? KBLocalized(@"Payment failed") : KBLocalized(@"Payment successful"))]; +// [KBHUD showInfo:(sta == !KBBizCodeSuccess ? KBLocalized(@"Payment failed") : KBLocalized(@"Payment successful"))]; if (sta == KBBizCodeSuccess) { [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; - [KBHUD showSuccess:@"Success"]; + [KBHUD showInfo:@"Success"]; + [[NSNotificationCenter defaultCenter] postNotificationName:KBIAPDidCompletePurchaseNotification object:nil]; if (handler) handler(KBLocalized(@"Success"), nil); }else if(sta == KBBizCodeReceiptError){ [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; diff --git a/keyBoard/Class/Pay/VC/KBJfPay.m b/keyBoard/Class/Pay/VC/KBJfPay.m index 616d92a..11394b4 100644 --- a/keyBoard/Class/Pay/VC/KBJfPay.m +++ b/keyBoard/Class/Pay/VC/KBJfPay.m @@ -10,6 +10,7 @@ #import "KBPayProductModel.h" #import "KBBizCode.h" #import "KBShopVM.h" +#import "IAPVerifyTransactionObj.h" static NSString * const kKBJfPayCellId = @"kKBJfPayCellId"; @interface KBJfPay () @@ -52,6 +53,10 @@ static NSString * const kKBJfPayCellId = @"kKBJfPayCellId"; self.filter = [[FGIAPProductsFilter alloc] init]; self.payVM = [PayVM new]; self.shopVM = [KBShopVM new]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleIAPPurchaseSuccess) + name:KBIAPDidCompletePurchaseNotification + object:nil]; self.data = @[]; self.selectedIndex = NSNotFound; self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_bg_icon"]]; @@ -151,6 +156,10 @@ static NSString * const kKBJfPayCellId = @"kKBJfPayCellId"; [self selectItemAtCurrentIndexAnimated:NO]; } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + #pragma mark - UICollectionView Delegate (ensure first show) - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath { if (![cell isKindOfClass:KBJfPayCell.class]) { return; } @@ -242,6 +251,10 @@ static NSString * const kKBJfPayCellId = @"kKBJfPayCellId"; }]; } +- (void)handleIAPPurchaseSuccess { + [self fetchWalletBalance]; +} + - (void)fetchInAppProductList { __weak typeof(self) weakSelf = self; [self.payVM fetchInAppProductsNeedShow:YES completion:^(NSInteger sta, NSString * _Nullable msg, NSArray * _Nullable products) { diff --git a/keyBoard/Class/Shop/VC/KBShopVC.m b/keyBoard/Class/Shop/VC/KBShopVC.m index b9ff82e..34991e0 100644 --- a/keyBoard/Class/Shop/VC/KBShopVC.m +++ b/keyBoard/Class/Shop/VC/KBShopVC.m @@ -70,6 +70,11 @@ static const CGFloat JXheightForHeaderInSection = 50; }]; [self fetchShopStylesWithHUD:YES]; + +} + +- (void)viewWillAppear:(BOOL)animated{ + [super viewWillAppear:animated]; [self fetchWalletBalanceWithHUD:NO]; }