添加键盘里的充值界面

This commit is contained in:
2025-12-17 16:22:41 +08:00
parent c6b4444589
commit dde8716262
9 changed files with 1038 additions and 14 deletions

View File

@@ -11,6 +11,10 @@ NS_ASSUME_NONNULL_BEGIN
/// VIP 订阅页(整体使用 UICollectionView上下滚动
@interface KBVipPay : BaseViewController
/// 通过键盘深链配置初始商品及是否自动发起购买
- (void)configureWithProductId:(nullable NSString *)productId
autoPurchase:(BOOL)autoPurchase;
@end
NS_ASSUME_NONNULL_END

View File

@@ -33,6 +33,10 @@ static NSString * const kKBVipReviewListCellId = @"kKBVipReviewListCellId";
@property (nonatomic, strong) UILabel *agreementLabel; //
@property (nonatomic, strong) UIButton *agreementButton; // Embership Agreement
@property (nonatomic, strong) PayVM *payVM;
@property (nonatomic, copy, nullable) NSString *pendingProductId;
@property (nonatomic, assign) BOOL pendingAutoPurchase;
@property (nonatomic, assign) BOOL hasTriggeredAutoPurchase;
@property (nonatomic, assign) BOOL viewVisible;
@end
@@ -104,7 +108,24 @@ static NSString * const kKBVipReviewListCellId = @"kKBVipReviewListCellId";
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.viewVisible = YES;
[self selectCurrentPlanAnimated:NO];
[self kb_triggerAutoPurchaseIfNeeded];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
self.viewVisible = NO;
}
#pragma mark - Deep Link Support
- (void)configureWithProductId:(NSString *)productId autoPurchase:(BOOL)autoPurchase {
self.pendingProductId = productId.length ? [productId copy] : nil;
self.pendingAutoPurchase = autoPurchase;
self.hasTriggeredAutoPurchase = NO;
[self kb_applyPendingPrefillIfNeeded];
[self kb_triggerAutoPurchaseIfNeeded];
}
#pragma mark - Data
@@ -126,7 +147,9 @@ static NSString * const kKBVipReviewListCellId = @"kKBVipReviewListCellId";
self.selectedIndex = self.plans.count > 0 ? 0 : NSNotFound;
[self.collectionView reloadData];
[self prepareStoreKitWithPlans:self.plans];
[self kb_applyPendingPrefillIfNeeded];
[self selectCurrentPlanAnimated:NO];
[self kb_triggerAutoPurchaseIfNeeded];
});
}];
}
@@ -164,6 +187,31 @@ static NSString * const kKBVipReviewListCellId = @"kKBVipReviewListCellId";
return plan;
}
- (void)kb_applyPendingPrefillIfNeeded {
if (self.pendingProductId.length == 0 || self.plans.count == 0) { return; }
__block NSInteger target = NSNotFound;
[self.plans enumerateObjectsUsingBlock:^(KBPayProductModel *obj, NSUInteger idx, BOOL *stop) {
if (![obj isKindOfClass:KBPayProductModel.class]) { return; }
if ([obj.productId isEqualToString:self.pendingProductId]) {
target = (NSInteger)idx;
*stop = YES;
}
}];
if (target != NSNotFound) {
self.selectedIndex = target;
}
}
- (void)kb_triggerAutoPurchaseIfNeeded {
if (!self.pendingAutoPurchase || self.hasTriggeredAutoPurchase || !self.viewVisible) { return; }
if (![self currentSelectedPlan]) { return; }
self.hasTriggeredAutoPurchase = YES;
self.pendingAutoPurchase = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self onTapPayButton];
});
}
- (NSString *)displayTitleForPlan:(KBPayProductModel *)plan {
if (!plan) { return @""; }
if (plan.productDescription.length) { return plan.productDescription; }