一次性配置内购服务
This commit is contained in:
@@ -36,13 +36,17 @@
|
|||||||
|
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||||
// 1. 配置内购服务
|
/// 1:配置国际化(统一使用集中管理的语言列表)
|
||||||
[[FGIAPManager shared] setConfigureWith:[IAPVerifyTransactionObj new]];
|
|
||||||
/// 2:配置国际化(统一使用集中管理的语言列表)
|
|
||||||
[KBLocalizationManager shared].supportedLanguageCodes = KBDefaultSupportedLanguageCodes();
|
[KBLocalizationManager shared].supportedLanguageCodes = KBDefaultSupportedLanguageCodes();
|
||||||
/// 3 : 处理token问题
|
/// 2 : 处理token问题(包括卸载重装场景下的 token 清理)
|
||||||
[[KBUserSessionManager shared] bootstrapIfNeeded];
|
[[KBUserSessionManager shared] bootstrapIfNeeded];
|
||||||
|
|
||||||
|
/// 3:如果当前已经是登录状态,则在启动时初始化一次内购服务。
|
||||||
|
/// 对于“首次登录”的场景,会在登录成功(见 KBLoginVM)后再进行一次配置。
|
||||||
|
if ([KBUserSessionManager shared].isLoggedIn) {
|
||||||
|
[[FGIAPManager shared] setConfigureWith:[IAPVerifyTransactionObj new]];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 首次安装/升级:重置“完全访问”记录,避免继承旧安装遗留在 Keychain 中的状态
|
// 首次安装/升级:重置“完全访问”记录,避免继承旧安装遗留在 Keychain 中的状态
|
||||||
static NSString *const kKBFullAccessRecordInitializedKey = @"KBFullAccessRecordInitialized";
|
static NSString *const kKBFullAccessRecordInitializedKey = @"KBFullAccessRecordInitialized";
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#import "AppleSignInManager.h"
|
#import "AppleSignInManager.h"
|
||||||
#import "KBNetworkManager.h"
|
#import "KBNetworkManager.h"
|
||||||
#import "KBAuthManager.h"
|
#import "KBAuthManager.h"
|
||||||
|
#import "FGIAPManager.h"
|
||||||
|
#import "IAPVerifyTransactionObj.h"
|
||||||
#import "KBAPI.h"
|
#import "KBAPI.h"
|
||||||
#import "KBUser.h"
|
#import "KBUser.h"
|
||||||
|
|
||||||
@@ -15,6 +17,14 @@
|
|||||||
|
|
||||||
@implementation KBLoginVM
|
@implementation KBLoginVM
|
||||||
|
|
||||||
|
/// 统一初始化内购(只执行一次)。既可以在“启动时已登录”的场景调用,也可以在“登录成功回调”里调用。
|
||||||
|
+ (void)kb_configureIAPIfNeeded {
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
[[FGIAPManager shared] setConfigureWith:[IAPVerifyTransactionObj new]];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
+ (instancetype)shared {
|
+ (instancetype)shared {
|
||||||
static KBLoginVM *vm; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ vm = [KBLoginVM new]; });
|
static KBLoginVM *vm; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ vm = [KBLoginVM new]; });
|
||||||
return vm;
|
return vm;
|
||||||
@@ -64,7 +74,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
[[KBUserSessionManager shared] handleLoginSuccessWithUser:user];
|
[[KBUserSessionManager shared] handleLoginSuccessWithUser:user];
|
||||||
completion(true,nil);
|
[KBLoginVM kb_configureIAPIfNeeded];
|
||||||
|
if (completion) completion(YES, nil);
|
||||||
// 保存登录态到共享钥匙串;供 App 与扩展共享
|
// 保存登录态到共享钥匙串;供 App 与扩展共享
|
||||||
// BOOL ok = [[KBAuthManager shared] saveAccessToken:user.token
|
// BOOL ok = [[KBAuthManager shared] saveAccessToken:user.token
|
||||||
// refreshToken:nil
|
// refreshToken:nil
|
||||||
@@ -99,7 +110,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
[[KBUserSessionManager shared] handleLoginSuccessWithUser:user];
|
[[KBUserSessionManager shared] handleLoginSuccessWithUser:user];
|
||||||
completion(true,nil);
|
[KBLoginVM kb_configureIAPIfNeeded];
|
||||||
|
if (completion) completion(YES, nil);
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +140,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
[[KBUserSessionManager shared] handleLoginSuccessWithUser:user];
|
[[KBUserSessionManager shared] handleLoginSuccessWithUser:user];
|
||||||
completion(true,nil);
|
[KBLoginVM kb_configureIAPIfNeeded];
|
||||||
|
if (completion) completion(YES, nil);
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)setConfigureWith:(id<FGIAPVerifyTransaction>)verifyTransaction{
|
- (void)setConfigureWith:(id<FGIAPVerifyTransaction>)verifyTransaction{
|
||||||
|
// 只初始化一次,避免重复向 SKPaymentQueue 注册多个观察者。
|
||||||
|
if (self->_iap != nil) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
self->_iap = [[FGIAPService alloc] initWithTransaction:verifyTransaction];
|
self->_iap = [[FGIAPService alloc] initWithTransaction:verifyTransaction];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user