Skip to content

Commit

Permalink
Release 0.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujg-00 committed Nov 8, 2021
1 parent fdb26fa commit 97cb782
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion SensorsABTest/SABConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#import "SABConstants.h"

// 当前版本号
NSString *const kSABLibVersion = @"0.1.3";
NSString *const kSABLibVersion = @"0.1.4";

// SA 最低支持版本
#if TARGET_OS_OSX
Expand Down
28 changes: 15 additions & 13 deletions SensorsABTest/SABManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,23 @@ - (void)fetchABTestWithModeType:(SABFetchABTestModeType)type paramName:(NSString
return;
}
if (![SABValidUtils isValidString:paramName]) {
dispatch_async(dispatch_get_main_queue(), ^{
if (type == SABFetchABTestModeTypeCache) {
completionHandler(defaultValue);
});
} else {
// fast 和 async 异步接口,统一主线程回调结果
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(defaultValue);
});
}
SABLogError(@"paramName: %@ error,paramName must be a valid string!", paramName);
return;
}

switch (type) {
case SABFetchABTestModeTypeCache: {
// 从缓存读取
id cacheValue = [self fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(cacheValue ? : defaultValue);
});
return;
return completionHandler(cacheValue ? : defaultValue);
}
case SABFetchABTestModeTypeFast: {
id cacheValue = [self fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
Expand All @@ -267,8 +269,8 @@ - (void)fetchABTestWithModeType:(SABFetchABTestModeType)type paramName:(NSString
case SABFetchABTestModeTypeAsync: {
// 异步请求
[self fetchAsyncABTestWithParamName:paramName defaultValue:defaultValue timeoutInterval:timeoutInterval completionHandler:completionHandler];
break;
}
break;
default:
break;
}
Expand Down Expand Up @@ -306,23 +308,23 @@ - (void)fetchAsyncABTestWithParamName:(NSString *)paramName defaultValue:(id)def
// 异步请求
SABExperimentRequest *requestData = [[SABExperimentRequest alloc] initWithBaseURL:self.configOptions.baseURL projectKey:self.configOptions.projectKey];
requestData.timeoutInterval = timeoutInterval;

__weak typeof(self) weakSelf = self;
[self.dataManager asyncFetchAllExperimentWithRequest:requestData completionHandler:^(SABFetchResultResponse *_Nullable responseData, NSError *_Nullable error) {
__strong typeof(weakSelf) strongSelf = weakSelf;

if (error || !responseData) {
SABLogError(@"asyncFetchAllExperimentWithRequest failure,error: %@", error);
// 切到主线程回调结果
// 请求失败,主线程回调结果
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(defaultValue);
});
return;
}

// 获取缓存并触发 $ABTestTrigger 事件
id cacheValue = [strongSelf fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];

// 切到主线程回调结果
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(cacheValue ? : defaultValue);
Expand Down
8 changes: 4 additions & 4 deletions SensorsABTest/SensorsABTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,27 @@ NS_ASSUME_NONNULL_BEGIN
/// 异步从服务端获取最新试验结果,默认 timeout 为 30 秒
/// @param paramName 试验参数名
/// @param defaultValue 默认结果
/// @param completionHandler 回调返回试验结果
/// @param completionHandler 主线程回调,返回试验结果
- (void)asyncFetchABTestWithParamName:(NSString *)paramName defaultValue:(id)defaultValue completionHandler:(void (^)(id _Nullable result))completionHandler;

/// 异步从服务端获取最新试验结果
/// @param paramName 试验参数名
/// @param defaultValue 默认结果
/// @param timeoutInterval 超时时间,单位为秒
/// @param completionHandler 回调返回试验结果
/// @param completionHandler 主线程回调,返回试验结果
- (void)asyncFetchABTestWithParamName:(NSString *)paramName defaultValue:(id)defaultValue timeoutInterval:(NSTimeInterval)timeoutInterval completionHandler:(void (^)(id _Nullable result))completionHandler;

/// 优先从缓存获取试验结果,如果无缓存试验,则异步从网络请求
/// @param paramName 试验参数名
/// @param defaultValue 默认值
/// @param completionHandler 回调返回试验结果
/// @param completionHandler 主线程回调,返回试验结果
- (void)fastFetchABTestWithParamName:(NSString *)paramName defaultValue:(id)defaultValue completionHandler:(void (^)(id _Nullable result))completionHandler;

/// 优先从缓存获取试验结果,如果无缓存试验,则异步从网络请求
/// @param paramName 试验参数名
/// @param defaultValue 默认值
/// @param timeoutInterval 超时时间,单位为秒
/// @param completionHandler 回调返回试验结果
/// @param completionHandler 主线程回调,返回试验结果
- (void)fastFetchABTestWithParamName:(NSString *)paramName defaultValue:(id)defaultValue timeoutInterval:(NSTimeInterval)timeoutInterval completionHandler:(void (^)(id _Nullable result))completionHandler;

/// 处理 url scheme 跳转打开 App
Expand Down
2 changes: 1 addition & 1 deletion SensorsABTesting.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SensorsABTesting'
s.version = "0.1.3"
s.version = "0.1.4"
s.summary = 'The official iOS/macOS SDK of Sensors A/B Testing.'
s.homepage = 'http://www.sensorsdata.cn'
s.license = { :type => 'Apache 2.0', :file => 'LICENSE' }
Expand Down

0 comments on commit 97cb782

Please sign in to comment.