Skip to content

Commit

Permalink
Release 2.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujg-00 committed Mar 23, 2021
1 parent e59ae42 commit 3664ddc
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 29 deletions.
11 changes: 9 additions & 2 deletions SensorsAnalyticsSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SensorsAnalyticsSDK"
s.version = "2.5.0"
s.version = "2.5.1"
s.summary = "The official iOS SDK of Sensors Analytics."
s.homepage = "http://www.sensorsdata.cn"
s.source = { :git => 'https://github.com/sensorsdata/sa-sdk-ios.git', :tag => "v#{s.version}" }
Expand All @@ -17,12 +17,19 @@ Pod::Spec.new do |s|
c.public_header_files = core_dir + "SensorsAnalyticsSDK.h", core_dir + "SensorsAnalyticsSDK+Public.h", core_dir + "SAAppExtensionDataManager.h", core_dir + "SASecurityPolicy.h", core_dir + "SAConfigOptions.h", core_dir + "SAConstants.h"
c.resource = 'SensorsAnalyticsSDK/SensorsAnalyticsSDK.bundle'
end

s.subspec 'Core' do |c|
c.dependency 'SensorsAnalyticsSDK/Common'
c.dependency 'SensorsAnalyticsSDK/Gesture'
end

# 支持 CAID 渠道匹配
s.subspec 'CAID' do |f|
f.dependency 'SensorsAnalyticsSDK/Core'
f.source_files = "SensorsAnalyticsSDK/CAID/**/*.{h,m}"
f.private_header_files = 'SensorsAnalyticsSDK/CAID/**/*.h'
end

# 手势采集
s.subspec 'Gesture' do |g|
g.dependency 'SensorsAnalyticsSDK/Common'
Expand Down
16 changes: 16 additions & 0 deletions SensorsAnalyticsSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@
FC23719523D0519A00DDD708 /* SALinkHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FC23719423D0519A00DDD708 /* SALinkHandlerTests.m */; };
FC3C58DA23BEEFB000D83BF4 /* SATrackTimerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FC3C58D923BEEFB000D83BF4 /* SATrackTimerTests.m */; };
FC80AB7C242CB17A006D1D25 /* SAIdentifierTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FC80AB7B242CB17A006D1D25 /* SAIdentifierTests.m */; };
FCEA7FBA25F8D95400C81687 /* SACAIDUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = FCEA7FB825F8D95400C81687 /* SACAIDUtils.m */; };
FCEA7FBB25F8D95400C81687 /* SACAIDUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = FCEA7FB925F8D95400C81687 /* SACAIDUtils.h */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -469,6 +471,8 @@
FC23719423D0519A00DDD708 /* SALinkHandlerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SALinkHandlerTests.m; sourceTree = "<group>"; };
FC3C58D923BEEFB000D83BF4 /* SATrackTimerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SATrackTimerTests.m; sourceTree = "<group>"; };
FC80AB7B242CB17A006D1D25 /* SAIdentifierTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SAIdentifierTests.m; sourceTree = "<group>"; };
FCEA7FB825F8D95400C81687 /* SACAIDUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SACAIDUtils.m; sourceTree = "<group>"; };
FCEA7FB925F8D95400C81687 /* SACAIDUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SACAIDUtils.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -898,6 +902,7 @@
children = (
F277F5B025CF9A43009B5CE6 /* AppPush */,
881A40D2253D7B4F00854F69 /* Core */,
FCEA7FB725F8D95400C81687 /* CAID */,
881A4224253D7B5E00854F69 /* Location */,
453FC62425EE3D6300591C47 /* Gesture */,
CB30C0AB22840F1B0004061D /* Resources */,
Expand Down Expand Up @@ -951,6 +956,15 @@
path = Resources;
sourceTree = "<group>";
};
FCEA7FB725F8D95400C81687 /* CAID */ = {
isa = PBXGroup;
children = (
FCEA7FB925F8D95400C81687 /* SACAIDUtils.h */,
FCEA7FB825F8D95400C81687 /* SACAIDUtils.m */,
);
path = CAID;
sourceTree = "<group>";
};
F2346B7D25E0AE5600AA3684 /* HookDelegate */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1088,6 +1102,7 @@
4D4DB2E725B7D1F300938842 /* SAReferrerManager.h in Headers */,
4D9E5DC925943BCE0095A0D0 /* SAApplicationStateSerializer.h in Headers */,
881A419B253D7B4F00854F69 /* SAConfigOptions.h in Headers */,
FCEA7FBB25F8D95400C81687 /* SACAIDUtils.h in Headers */,
4D9E5DC325943BCE0095A0D0 /* SATypeDescription.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1317,6 +1332,7 @@
4D9E5DA925943BCD0095A0D0 /* SAVisualizedConnection.m in Sources */,
A8A87E4D2568EBD500E16895 /* SARemoteConfigManager.m in Sources */,
4D9E5DBA25943BCE0095A0D0 /* SAJSTouchEventView.m in Sources */,
FCEA7FBA25F8D95400C81687 /* SACAIDUtils.m in Sources */,
4D9E5DC825943BCE0095A0D0 /* SAValueTransformers.m in Sources */,
881A4210253D7B5000854F69 /* SAIdentifier.m in Sources */,
4D9E5DC725943BCE0095A0D0 /* SAVisualizedUtils.m in Sources */,
Expand Down
29 changes: 29 additions & 0 deletions SensorsAnalyticsSDK/CAID/SACAIDUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// SACAIDUtils.h
// SensorsAnalyticsSDK
//
// Created by 彭远洋 on 2021/3/4.
// Copyright © 2021 Sensors Data Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface SACAIDUtils : NSObject

@end

NS_ASSUME_NONNULL_END
96 changes: 96 additions & 0 deletions SensorsAnalyticsSDK/CAID/SACAIDUtils.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// SACAIDUtils.m
// SensorsAnalyticsSDK
//
// Created by 彭远洋 on 2021/3/4.
// Copyright © 2021 Sensors Data Co., Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#if ! __has_feature(objc_arc)
#error This file must be compiled with ARC. Either turn on ARC for the project or use -fobjc-arc flag on this file.
#endif

#import "SACAIDUtils.h"
#import "SASwizzle.h"
#import "SAFileStore.h"
#import "SALog.h"

static NSString *const kSACAIDCacheKey = @"com.sensorsdata.caid.cache";
static NSDictionary *caid;

@implementation SACAIDUtils

+ (NSDictionary *)CAIDInfo {
Class CAID = NSClassFromString(@"CAID");
if (!CAID) {
SALogError(@"您未集成 CAID SDK,请按照集成文档正确集成 CAID SDK 后调用 getCAIDAsyncly 接口获取 CAID 信息");
return nil;
}
if (!caid) {
caid = [SAFileStore unarchiveWithFileName:kSACAIDCacheKey];
}
if (caid.allKeys.count == 0 ) {
SALogError(@"未获取到缓存的 CAID 信息,请检查是否正确集成 CAID SDK,并调用 getCAIDAsyncly 接口获取 CAID 信息");
return nil;
}
return caid;
}

#pragma mark - swizzled Method
+ (void)load {
Class CAID = NSClassFromString(@"CAID");
if (!CAID) {
NSAssert(CAID, @"您未集成 CAID SDK,请按照集成文档正确集成 CAID SDK 后调用 getCAIDAsyncly 接口获取 CAID 信息");
return;
}
SEL origSel = NSSelectorFromString(@"getCAIDAsyncly:");
SEL swizzledSel = NSSelectorFromString(@"sensorsdata_getCAIDAsyncly:");
[CAID sa_swizzleMethod:origSel withClass:SACAIDUtils.class withMethod:swizzledSel error:nil];
}

- (void)sensorsdata_getCAIDAsyncly:(void(^)(id error, id caidStruct))callback {
[self sensorsdata_getCAIDAsyncly:^(id _Nonnull error, id _Nonnull caidStruct) {
NSInteger code = [SACAIDUtils invokeError:error selString:@"code"];
if (code == 0) {
// CAIDErrorCodeNone = 0, 无错误
NSMutableDictionary *caid = [NSMutableDictionary dictionary];
caid[@"caid"] = (NSString *)[SACAIDUtils invokeObject:caidStruct selString:@"caid"];
caid[@"caid_version"] = (NSNumber *)[SACAIDUtils invokeObject:caidStruct selString:@"version"];
caid[@"last_caid"] = (NSString *)[SACAIDUtils invokeObject:caidStruct selString:@"lastVersionCAID"];
caid[@"last_caid_version"] = (NSNumber *)[SACAIDUtils invokeObject:caidStruct selString:@"lastVersion"];
// 客户每次调用 getCAIDAsyncly 方法成功后都会更新本地 CAID 信息
[SAFileStore archiveWithFileName:kSACAIDCacheKey value:caid];
}
callback(error, caidStruct);
}];
}

+ (NSInteger)invokeError:(id)obj selString:(NSString *)selString {
SEL sel = NSSelectorFromString(selString);
if ([obj respondsToSelector:sel]) {
return ((NSInteger (*)(id, SEL))[obj methodForSelector:sel])(obj, sel);
}
return -1;
}

+ (id)invokeObject:(id)obj selString:(NSString *)selString {
SEL sel = NSSelectorFromString(selString);
if ([obj respondsToSelector:sel]) {
return ((id (*)(id, SEL))[obj methodForSelector:sel])(obj, sel);
}
return nil;
}

@end
7 changes: 7 additions & 0 deletions SensorsAnalyticsSDK/Core/Builder/SAIdentifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (NSString *)idfa;

/**
获取设备的 IDFV
@return idfv
*/
+ (NSString *)idfv;

/**
生成匿名 Id(设备 Id):IDFA -> IDFV -> UUID
Expand Down
6 changes: 5 additions & 1 deletion SensorsAnalyticsSDK/Core/Builder/SAIdentifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,16 @@ + (NSString *)idfa {
return nil;
}

+ (NSString *)idfv {
return [UIDevice currentDevice].identifierForVendor.UUIDString;;
}

+ (NSString *)uniqueHardwareId {
NSString *distinctId = [self idfa];

// 没有IDFA,则使用IDFV
if (!distinctId) {
distinctId = [UIDevice currentDevice].identifierForVendor.UUIDString;
distinctId = [self idfv];
}

// 没有IDFV,则使用UUID
Expand Down
Loading

0 comments on commit 3664ddc

Please sign in to comment.