添加键盘里的充值界面
This commit is contained in:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user