Skip to content

Commit 9d83f35

Browse files
committed
Release 0.1.1
1 parent 5c26962 commit 9d83f35

8 files changed

Lines changed: 46 additions & 62 deletions

File tree

Example/Example-iOS/AppDelegate.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ - (void)startSensorsAnalyticsSDKWithConfigOptions:(NSDictionary *)launchOptions
4141
options.enableVisualizedAutoTrack = YES;
4242
options.enableJavaScriptBridge = YES;
4343
options.enableLog = YES;
44+
options.flushNetworkPolicy = SensorsAnalyticsNetworkTypeALL;
45+
4446
[SensorsAnalyticsSDK startWithConfigOptions:options];
45-
[[SensorsAnalyticsSDK sharedInstance] setFlushNetworkPolicy:SensorsAnalyticsNetworkTypeALL];
4647
}
4748

4849
- (void)startSensorsABTest {

Example/Example-macOS/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ - (void)startSensorsAnalyticsSDKWithLaunching:(NSNotification *)aNotification {
3636
SAConfigOptions *options = [[SAConfigOptions alloc] initWithServerURL:SADefaultServerURL launchOptions:nil];
3737
options.enableJavaScriptBridge = YES;
3838
options.enableLog = YES;
39+
options.flushNetworkPolicy = SensorsAnalyticsNetworkTypeALL;
40+
3941
[SensorsAnalyticsSDK startWithConfigOptions:options];
40-
41-
[[SensorsAnalyticsSDK sharedInstance] setFlushNetworkPolicy:SensorsAnalyticsNetworkTypeALL];
4242
}
4343

4444
- (void)startSensorsABTest {

Podfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ target 'Example-iOS' do
1212
# pod 'SensorsABTesting'
1313

1414
pod 'SensorsABTesting', :path => './'
15+
pod 'SensorsAnalyticsSDK', >= 3.1.1
1516
end
1617

1718

@@ -23,4 +24,5 @@ target 'Example-macOS' do
2324
# pod 'SensorsABTesting'
2425

2526
pod 'SensorsABTesting', :path => './'
27+
pod 'SensorsAnalyticsSDK', >= 3.1.1
2628
end

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.0";
28+
NSString *const kSABLibVersion = @"0.1.1";
2929

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

SensorsABTest/SABManager.m

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -241,54 +241,42 @@ - (void)fetchABTestWithModeType:(SABFetchABTestModeType)type paramName:(NSString
241241
SABLogError(@"paramName: %@ error,paramName must be a valid string!", paramName);
242242
return;
243243
}
244-
245-
dispatch_block_t fetchABTestBlock = ^() {
246-
switch (type) {
247-
case SABFetchABTestModeTypeCache: {
248-
// 从缓存读取
249-
id cacheValue = [self fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
250-
return completionHandler(cacheValue ? : defaultValue);
251-
}
252-
case SABFetchABTestModeTypeFast: {
253-
id cacheValue = [self fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
254-
if (cacheValue) {
255-
return completionHandler(cacheValue);
256-
}
257-
[self fetchAsyncABTestWithParamName:paramName defaultValue:defaultValue timeoutInterval:timeoutInterval completionHandler:completionHandler];
258-
break;
259-
}
260-
case SABFetchABTestModeTypeAsync: {
261-
// 异步请求
262-
[self fetchAsyncABTestWithParamName:paramName defaultValue:defaultValue timeoutInterval:timeoutInterval completionHandler:completionHandler];
244+
245+
switch (type) {
246+
case SABFetchABTestModeTypeCache: {
247+
// 从缓存读取
248+
id cacheValue = [self fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
249+
return completionHandler(cacheValue ? : defaultValue);
250+
}
251+
case SABFetchABTestModeTypeFast: {
252+
id cacheValue = [self fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
253+
if (cacheValue) {
254+
dispatch_async(dispatch_get_main_queue(), ^{
255+
completionHandler(cacheValue);
256+
});
257+
return;
263258
}
264-
break;
265-
default:
266-
break;
259+
[self fetchAsyncABTestWithParamName:paramName defaultValue:defaultValue timeoutInterval:timeoutInterval completionHandler:completionHandler];
260+
break;
267261
}
268-
};
269-
270-
dispatch_queue_t saSerialQueue = [SABBridge saSerialQueue];
271-
if (saSerialQueue) {
272-
// Cache 获取试验,同步执行
273-
if (type == SABFetchABTestModeTypeCache) {
274-
dispatch_sync(saSerialQueue, fetchABTestBlock);
275-
} else {
276-
dispatch_async(saSerialQueue, fetchABTestBlock);
262+
case SABFetchABTestModeTypeAsync: {
263+
// 异步请求
264+
[self fetchAsyncABTestWithParamName:paramName defaultValue:defaultValue timeoutInterval:timeoutInterval completionHandler:completionHandler];
277265
}
278-
} else {
279-
fetchABTestBlock();
266+
break;
267+
default:
268+
break;
280269
}
281270
}
282271

283272
/// 获取缓存试验
284273
- (nullable id)fetchCacheABTestWithParamName:(NSString *)paramName defaultValue:(id)defaultValue {
285-
286274
if (![SABValidUtils isValidString:paramName]) {
287275
SABLogError(@"paramName::%@ error,paramName must be a valid string!", paramName);
288276
return nil;
289277
}
290278
SABExperimentResult *resultData = [self.dataManager cachedExperimentResultWithParamName:paramName];
291-
279+
292280
if (!resultData) {
293281
SABLogWarn(@"The cache experiment result is empty, paramName: %@", paramName);
294282
return nil;
@@ -300,7 +288,7 @@ - (nullable id)fetchCacheABTestWithParamName:(NSString *)paramName defaultValue:
300288
SABLogWarn(@"The experiment result type is inconsistent with the defaultValue type of the interface setting, paramName: %@, experiment result type: %@, defaultValue type: %@", paramName, resulTypeString, defaultValueTypeString);
301289
return nil;
302290
}
303-
291+
304292
if (!resultData.isWhiteList) {
305293
// 埋点
306294
[self trackABTestWithData:resultData];
@@ -313,19 +301,23 @@ - (void)fetchAsyncABTestWithParamName:(NSString *)paramName defaultValue:(id)def
313301
// 异步请求
314302
SABExperimentRequest *requestData = [[SABExperimentRequest alloc] initWithBaseURL:self.configOptions.baseURL projectKey:self.configOptions.projectKey];
315303
requestData.timeoutInterval = timeoutInterval;
304+
305+
__weak typeof(self) weakSelf = self;
316306
[self.dataManager asyncFetchAllExperimentWithRequest:requestData completionHandler:^(SABFetchResultResponse *_Nullable responseData, NSError *_Nullable error) {
307+
__strong typeof(weakSelf) strongSelf = weakSelf;
308+
317309
if (error || !responseData) {
318310
SABLogError(@"asyncFetchAllExperimentWithRequest failure,error: %@", error);
319311
completionHandler(defaultValue);
320312
return;
321313
}
322314

323315
// 获取缓存并触发 $ABTestTrigger 事件
324-
id cacheValue = [self fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
316+
id cacheValue = [strongSelf fetchCacheABTestWithParamName:paramName defaultValue:defaultValue];
325317

326318
// 切到主线程回调结果
327319
dispatch_async(dispatch_get_main_queue(), ^{
328-
completionHandler(cacheValue ?: defaultValue);
320+
completionHandler(cacheValue ? : defaultValue);
329321
});
330322
}];
331323
}
@@ -339,21 +331,19 @@ - (void)fetchAllABTestResult {
339331
/// @param times 最大次数
340332
- (void)fetchAllABTestResultWithTimes:(NSInteger)times {
341333
NSInteger fetchIndex = times - 1;
342-
334+
343335
SABExperimentRequest *requestData = [[SABExperimentRequest alloc] initWithBaseURL:self.configOptions.baseURL projectKey:self.configOptions.projectKey];
344-
345-
[self.dataManager asyncFetchAllExperimentWithRequest:requestData completionHandler:^(SABFetchResultResponse * _Nullable responseData, NSError * _Nullable error) {
346-
336+
337+
[self.dataManager asyncFetchAllExperimentWithRequest:requestData completionHandler:^(SABFetchResultResponse *_Nullable responseData, NSError *_Nullable error) {
347338
if (fetchIndex <= 0 || !error) {
348339
return;
349340
}
350341
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kSABAsyncFetchExperimentRetryIntervalTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
351-
[self fetchAllABTestResultWithTimes:fetchIndex];
352-
});
342+
[self fetchAllABTestResultWithTimes:fetchIndex];
343+
});
353344
}];
354345
}
355346

356-
357347
#pragma mark - action
358348
/// track $ABTestTrigger
359349
- (void)trackABTestWithData:(SABExperimentResult *)resultData {
@@ -388,17 +378,15 @@ - (void)trackABTestWithData:(SABExperimentResult *)resultData {
388378
properties[kSABLoginId] = userIdenty.loginId;
389379
properties[kSABDistinctId] = userIdenty.distinctId;
390380
properties[kSABAnonymousId] = userIdenty.anonymousId;
391-
381+
392382
static dispatch_once_t onceToken;
393383
dispatch_once(&onceToken, ^{
394384
// 首次触发事件,添加版本号
395385
NSString *libVersion = [NSString stringWithFormat:@"%@:%@", kSABLibPrefix, kSABLibVersion];
396386
properties[kSABLibPluginVersion] = @[libVersion];
397387
});
398388

399-
dispatch_async(dispatch_get_main_queue(), ^{
400-
[SABBridge track:kSABTriggerEventName properties:properties];
401-
});
389+
[SABBridge track:kSABTriggerEventName properties:properties];
402390
}
403391

404392
/// 开始更新计时

SensorsABTest/SABridge/SABBridge.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ NS_ASSUME_NONNULL_BEGIN
4343
/// SA SDK 版本
4444
@property (class, nonatomic, copy, readonly) NSString *libVersion;
4545

46-
@property (class, nonatomic, strong, readonly) dispatch_queue_t saSerialQueue;
47-
4846
/// 调用 track 接口,追踪一个带有属性的 event
4947
/// @param eventName 事件名称
5048
/// @param properties 事件属性

SensorsABTest/SABridge/SABBridge.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,9 @@ + (NSDictionary *)presetProperties {
7070
return [self propertyWithName:@"getPresetProperties"];
7171
}
7272

73-
+ (dispatch_queue_t)saSerialQueue {
74-
dispatch_queue_t serialQueue = [self propertyWithName:@"serialQueue"];
75-
return serialQueue;
76-
}
77-
7873
/// 根据方法名获取属性
7974
/// @param name 名称
80-
+ (instancetype)propertyWithName:(NSString *)name {
75+
+ (id)propertyWithName:(NSString *)name {
8176
id sa = [self sensorsAnalyticsInstance];
8277
if (!sa) {
8378
SABLogWarn(@"Get SensorsAnalyticsSDK.sharedIntance failed");

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.0"
3+
s.version = "0.1.1"
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)