Skip to content

Commit 97cb782

Browse files
committed
Release 0.1.4
1 parent fdb26fa commit 97cb782

4 files changed

Lines changed: 21 additions & 19 deletions

File tree

SensorsABTest/SABConstants.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#import "SABConstants.h"
2626

2727
// 当前版本号
28-
NSString *const kSABLibVersion = @"0.1.3";
28+
NSString *const kSABLibVersion = @"0.1.4";
2929

3030
// SA 最低支持版本
3131
#if TARGET_OS_OSX

SensorsABTest/SABManager.m

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,23 @@ - (void)fetchABTestWithModeType:(SABFetchABTestModeType)type paramName:(NSString
237237
return;
238238
}
239239
if (![SABValidUtils isValidString:paramName]) {
240-
dispatch_async(dispatch_get_main_queue(), ^{
240+
if (type == SABFetchABTestModeTypeCache) {
241241
completionHandler(defaultValue);
242-
});
242+
} else {
243+
// fast 和 async 异步接口,统一主线程回调结果
244+
dispatch_async(dispatch_get_main_queue(), ^{
245+
completionHandler(defaultValue);
246+
});
247+
}
243248
SABLogError(@"paramName: %@ error,paramName must be a valid string!", paramName);
244249
return;
245250
}
246-
251+
247252
switch (type) {
248253
case SABFetchABTestModeTypeCache: {
249254
// 从缓存读取
250255
id cacheValue = [self fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
251-
dispatch_async(dispatch_get_main_queue(), ^{
252-
completionHandler(cacheValue ? : defaultValue);
253-
});
254-
return;
256+
return completionHandler(cacheValue ? : defaultValue);
255257
}
256258
case SABFetchABTestModeTypeFast: {
257259
id cacheValue = [self fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
@@ -267,8 +269,8 @@ - (void)fetchABTestWithModeType:(SABFetchABTestModeType)type paramName:(NSString
267269
case SABFetchABTestModeTypeAsync: {
268270
// 异步请求
269271
[self fetchAsyncABTestWithParamName:paramName defaultValue:defaultValue timeoutInterval:timeoutInterval completionHandler:completionHandler];
272+
break;
270273
}
271-
break;
272274
default:
273275
break;
274276
}
@@ -306,23 +308,23 @@ - (void)fetchAsyncABTestWithParamName:(NSString *)paramName defaultValue:(id)def
306308
// 异步请求
307309
SABExperimentRequest *requestData = [[SABExperimentRequest alloc] initWithBaseURL:self.configOptions.baseURL projectKey:self.configOptions.projectKey];
308310
requestData.timeoutInterval = timeoutInterval;
309-
311+
310312
__weak typeof(self) weakSelf = self;
311313
[self.dataManager asyncFetchAllExperimentWithRequest:requestData completionHandler:^(SABFetchResultResponse *_Nullable responseData, NSError *_Nullable error) {
312314
__strong typeof(weakSelf) strongSelf = weakSelf;
313-
315+
314316
if (error || !responseData) {
315317
SABLogError(@"asyncFetchAllExperimentWithRequest failure,error: %@", error);
316-
// 切到主线程回调结果
318+
// 请求失败,主线程回调结果
317319
dispatch_async(dispatch_get_main_queue(), ^{
318320
completionHandler(defaultValue);
319321
});
320322
return;
321323
}
322-
324+
323325
// 获取缓存并触发 $ABTestTrigger 事件
324326
id cacheValue = [strongSelf fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
325-
327+
326328
// 切到主线程回调结果
327329
dispatch_async(dispatch_get_main_queue(), ^{
328330
completionHandler(cacheValue ? : defaultValue);

SensorsABTest/SensorsABTest.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,27 @@ NS_ASSUME_NONNULL_BEGIN
4141
/// 异步从服务端获取最新试验结果,默认 timeout 为 30 秒
4242
/// @param paramName 试验参数名
4343
/// @param defaultValue 默认结果
44-
/// @param completionHandler 回调返回试验结果
44+
/// @param completionHandler 主线程回调,返回试验结果
4545
- (void)asyncFetchABTestWithParamName:(NSString *)paramName defaultValue:(id)defaultValue completionHandler:(void (^)(id _Nullable result))completionHandler;
4646

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

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

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

6767
/// 处理 url scheme 跳转打开 App

SensorsABTesting.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'SensorsABTesting'
3-
s.version = "0.1.3"
3+
s.version = "0.1.4"
44
s.summary = 'The official iOS/macOS SDK of Sensors A/B Testing.'
55
s.homepage = 'http://www.sensorsdata.cn'
66
s.license = { :type => 'Apache 2.0', :file => 'LICENSE' }

0 commit comments

Comments
 (0)