处理storkit2
This commit is contained in:
@@ -4,13 +4,12 @@
|
||||
|
||||
#import "KBJfPay.h"
|
||||
#import "KBJfPayCell.h"
|
||||
#import "FGIAPProductsFilter.h"
|
||||
#import "FGIAPManager.h"
|
||||
#import "PayVM.h"
|
||||
#import "KBPayProductModel.h"
|
||||
#import "KBBizCode.h"
|
||||
#import "KBShopVM.h"
|
||||
#import "IAPVerifyTransactionObj.h"
|
||||
#import "keyBoard-Swift.h"
|
||||
static NSString * const kKBJfPayCellId = @"kKBJfPayCellId";
|
||||
|
||||
@interface KBJfPay () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
||||
@@ -40,7 +39,6 @@ static NSString * const kKBJfPayCellId = @"kKBJfPayCellId";
|
||||
@property (nonatomic, strong) NSArray<KBPayProductModel *> *data; // In-App 商品展示数据
|
||||
@property (nonatomic, assign) NSInteger selectedIndex; // 当前选中项
|
||||
|
||||
@property (nonatomic, strong) FGIAPProductsFilter *filter;
|
||||
@property (nonatomic, strong) PayVM *payVM;
|
||||
@property (nonatomic, strong) KBShopVM *shopVM;
|
||||
|
||||
@@ -50,7 +48,6 @@ static NSString * const kKBJfPayCellId = @"kKBJfPayCellId";
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.filter = [[FGIAPProductsFilter alloc] init];
|
||||
self.payVM = [PayVM new];
|
||||
self.shopVM = [KBShopVM new];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
@@ -272,11 +269,25 @@ static NSString * const kKBJfPayCellId = @"kKBJfPayCellId";
|
||||
self.data = products ?: @[];
|
||||
self.selectedIndex = self.data.count > 0 ? 0 : NSNotFound;
|
||||
[self.collectionView reloadData];
|
||||
[self prepareStoreKitWithProducts:self.data];
|
||||
[self selectItemAtCurrentIndexAnimated:NO];
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)prepareStoreKitWithProducts:(NSArray<KBPayProductModel *> *)products {
|
||||
if (![products isKindOfClass:NSArray.class] || products.count == 0) { return; }
|
||||
NSMutableArray<NSString *> *ids = [NSMutableArray array];
|
||||
for (KBPayProductModel *item in products) {
|
||||
if (![item isKindOfClass:KBPayProductModel.class]) { continue; }
|
||||
if (item.productId.length) {
|
||||
[ids addObject:item.productId];
|
||||
}
|
||||
}
|
||||
if (ids.count == 0) { return; }
|
||||
[[KBStoreKitBridge shared] prepareWithProductIds:ids completion:nil];
|
||||
}
|
||||
|
||||
- (KBPayProductModel *)currentSelectedProductItem {
|
||||
if (self.selectedIndex == NSNotFound) { return nil; }
|
||||
if (self.selectedIndex < 0 || self.selectedIndex >= self.data.count) { return nil; }
|
||||
@@ -315,28 +326,12 @@ static NSString * const kKBJfPayCellId = @"kKBJfPayCellId";
|
||||
}
|
||||
[KBHUD show];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.filter requestProductsWith:[NSSet setWithObject:productId] completion:^(NSArray<SKProduct *> * _Nonnull products) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__strong typeof(weakSelf) self = weakSelf;
|
||||
if (!self) { return; }
|
||||
SKProduct *match = nil;
|
||||
for (SKProduct *product in products) {
|
||||
if ([product.productIdentifier isEqualToString:productId]) {
|
||||
match = product;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!match) {
|
||||
[KBHUD dismiss];
|
||||
[KBHUD showInfo:KBLocalized(@"Unable to load product information")];
|
||||
return;
|
||||
}
|
||||
[[FGIAPManager shared].iap buyProduct:match onCompletion:^(NSString * _Nonnull message, FGIAPManagerPurchaseRusult result) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// [KBHUD dismiss];
|
||||
});
|
||||
}];
|
||||
});
|
||||
[[KBStoreKitBridge shared] purchaseWithProductId:productId completion:^(BOOL success, NSString * _Nullable message) {
|
||||
__strong typeof(weakSelf) self = weakSelf;
|
||||
NSString *tip = message.length ? message : (success ? KBLocalized(@"Payment successful") : KBLocalized(@"Payment failed"));
|
||||
[KBHUD dismiss];
|
||||
[KBHUD showInfo:tip];
|
||||
(void)self;
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user