添加键盘里的充值界面
This commit is contained in:
@@ -187,10 +187,20 @@
|
||||
} else if ([host isEqualToString:@"settings"]) { // kbkeyboard://settings
|
||||
[self kb_openAppSettings];
|
||||
return YES;
|
||||
}else if ([host isEqualToString:@"recharge"]) { // kbkeyboard://settings
|
||||
// [self kb_openAppSettings];
|
||||
// [KBHUD showInfo:@"去充值"];
|
||||
}else if ([host isEqualToString:@"recharge"]) { // kbkeyboard://recharge
|
||||
NSDictionary<NSString *, NSString *> *params = [self kb_queryParametersFromURL:url];
|
||||
NSString *productId = params[@"productId"];
|
||||
BOOL autoPay = NO;
|
||||
NSString *autoFlag = params[@"autoPay"];
|
||||
if ([autoFlag respondsToSelector:@selector(boolValue)]) {
|
||||
autoPay = autoFlag.boolValue;
|
||||
}
|
||||
NSString *action = params[@"action"].lowercaseString;
|
||||
if ([action isEqualToString:@"autopay"]) {
|
||||
autoPay = YES;
|
||||
}
|
||||
KBVipPay *vc = [[KBVipPay alloc] init];
|
||||
[vc configureWithProductId:productId autoPurchase:autoPay];
|
||||
[KB_CURRENT_NAV pushViewController:vc animated:true];
|
||||
return YES;
|
||||
}
|
||||
@@ -199,6 +209,19 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)kb_queryParametersFromURL:(NSURL *)url {
|
||||
if (!url) { return @{}; }
|
||||
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
|
||||
NSArray<NSURLQueryItem *> *items = components.queryItems ?: @[];
|
||||
if (items.count == 0) { return @{}; }
|
||||
NSMutableDictionary<NSString *, NSString *> *dict = [NSMutableDictionary dictionaryWithCapacity:items.count];
|
||||
for (NSURLQueryItem *item in items) {
|
||||
if (item.name.length == 0) { continue; }
|
||||
dict[item.name] = item.value ?: @"";
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
- (void)kb_presentLoginSheetIfNeeded {
|
||||
// 已登录则不提示
|
||||
// BOOL loggedIn = ([AppleSignInManager shared].storedUserIdentifier.length > 0);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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