Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watchOS 支持 #120

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
205 changes: 120 additions & 85 deletions SensorsAnalyticsSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,134 +1,169 @@
Pod::Spec.new do |s|
s.name = "SensorsAnalyticsSDK"
s.version = "4.5.14"
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}" }
s.name = "SensorsAnalyticsSDK"
s.version = "4.5.14"
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}" }
s.license = { :type => "Apache License, Version 2.0" }
s.author = { "Yuhan ZOU" => "[email protected]" }
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.13'
s.default_subspec = 'Core'
s.frameworks = 'Foundation', 'SystemConfiguration'

s.libraries = 'icucore', 'z'
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.13"
s.watchos.deployment_target = "7.0"

s.subspec '__Store' do |ss|
ss.source_files = 'SensorsAnalyticsSDK/Store/*.{h,m}'
ss.public_header_files = 'SensorsAnalyticsSDK/Store/SABaseStoreManager.h', 'SensorsAnalyticsSDK/Store/SAStorePlugin.h', 'SensorsAnalyticsSDK/Store/SAAESStorePlugin.h'
s.default_subspec = "Core"

s.subspec "__Store" do |ss|
ss.source_files = "SensorsAnalyticsSDK/Store/*.{h,m}"
ss.public_header_files = [
"SensorsAnalyticsSDK/Store/SABaseStoreManager.h",
"SensorsAnalyticsSDK/Store/SAStorePlugin.h",
"SensorsAnalyticsSDK/Store/SAAESStorePlugin.h",
]
end

s.subspec 'Base' do |b|
core_dir = "SensorsAnalyticsSDK/Core/"
b.source_files = core_dir + "**/*.{h,m}"
b.exclude_files = core_dir + "SAAlertController.h", core_dir + "SAAlertController.m"
b.public_header_files = core_dir + "SensorsAnalyticsSDK.h", core_dir + "SensorsAnalyticsSDK+Public.h", core_dir + "SASecurityPolicy.h", core_dir + "SAConfigOptions.h", core_dir + "SAConstants.h", core_dir + "PropertyPlugin/SAPropertyPlugin.h"
b.ios.frameworks = 'CoreTelephony'
b.dependency 'SensorsAnalyticsSDK/__Store'
s.subspec "Base" do |b|
b.source_files = "SensorsAnalyticsSDK/Core/**/*.{h,m}"
b.exclude_files = "SensorsAnalyticsSDK/Core/SAAlertController.{h,m}"
b.public_header_files = [
"SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.h",
"SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK+Public.h",
"SensorsAnalyticsSDK/Core/SASecurityPolicy.h",
"SensorsAnalyticsSDK/Core/SAConfigOptions.h",
"SensorsAnalyticsSDK/Core/SAConstants.h",
"SensorsAnalyticsSDK/Core/PropertyPlugin/SAPropertyPlugin.h",
]

b.ios.frameworks = "CoreTelephony", "SystemConfiguration"
b.osx.frameworks = "SystemConfiguration"
b.watchos.frameworks = "WatchKit"

b.dependency "SensorsAnalyticsSDK/__Store"
end

s.subspec 'Extension' do |e|
e.dependency 'SensorsAnalyticsSDK/Base'
s.subspec "Extension" do |e|
e.dependency "SensorsAnalyticsSDK/Base"
end

s.subspec 'Common' do |c|
c.dependency 'SensorsAnalyticsSDK/Extension'
c.public_header_files = 'SensorsAnalyticsSDK/JSBridge/SensorsAnalyticsSDK+JavaScriptBridge.h'
c.source_files = 'SensorsAnalyticsSDK/Core/SAAlertController.{h,m}', 'SensorsAnalyticsSDK/JSBridge/**/*.{h,m}'
c.ios.source_files = 'SensorsAnalyticsSDK/RemoteConfig/**/*.{h,m}', 'SensorsAnalyticsSDK/ChannelMatch/**/*.{h,m}', 'SensorsAnalyticsSDK/Encrypt/**/*.{h,m}', 'SensorsAnalyticsSDK/Deeplink/**/*.{h,m}', 'SensorsAnalyticsSDK/DebugMode/**/*.{h,m}', 'SensorsAnalyticsSDK/Core/SAAlertController.h', 'SensorsAnalyticsSDK/UIRelated/**/*.{h,m}'
c.ios.public_header_files = 'SensorsAnalyticsSDK/{Encrypt,RemoteConfig,ChannelMatch,Deeplink,DebugMode}/{SAConfigOptions,SensorsAnalyticsSDK}+*.h', 'SensorsAnalyticsSDK/Encrypt/SAEncryptProtocol.h', 'SensorsAnalyticsSDK/Encrypt/SASecretKey.h', 'SensorsAnalyticsSDK/Deeplink/SASlinkCreator.h', 'SensorsAnalyticsSDK/UIRelated/UIView+SensorsAnalytics.h'
s.subspec "Common" do |c|
c.source_files = [
"SensorsAnalyticsSDK/Core/SAAlertController.{h,m}",
"SensorsAnalyticsSDK/JSBridge/**/*.{h,m}",
]
c.public_header_files = "SensorsAnalyticsSDK/JSBridge/SensorsAnalyticsSDK+JavaScriptBridge.h"

c.ios.source_files = [
"SensorsAnalyticsSDK/RemoteConfig/**/*.{h,m}",
"SensorsAnalyticsSDK/ChannelMatch/**/*.{h,m}",
"SensorsAnalyticsSDK/Encrypt/**/*.{h,m}",
"SensorsAnalyticsSDK/Deeplink/**/*.{h,m}",
"SensorsAnalyticsSDK/DebugMode/**/*.{h,m}",
"SensorsAnalyticsSDK/UIRelated/**/*.{h,m}",
]
c.ios.public_header_files = [
"SensorsAnalyticsSDK/{Encrypt,RemoteConfig,ChannelMatch,Deeplink,DebugMode}/{SAConfigOptions,SensorsAnalyticsSDK}+*.h",
"SensorsAnalyticsSDK/Encrypt/SAEncryptProtocol.h",
"SensorsAnalyticsSDK/Encrypt/SASecretKey.h",
"SensorsAnalyticsSDK/Deeplink/SASlinkCreator.h",
"SensorsAnalyticsSDK/UIRelated/UIView+SensorsAnalytics.h",
]

c.dependency "SensorsAnalyticsSDK/Extension"
end

s.subspec 'Core' do |c|
c.ios.dependency 'SensorsAnalyticsSDK/Visualized'
c.osx.dependency 'SensorsAnalyticsSDK/Common'
s.subspec "Core" do |c|
c.ios.dependency "SensorsAnalyticsSDK/Visualized"
c.osx.dependency "SensorsAnalyticsSDK/Common"
c.watchos.dependency "SensorsAnalyticsSDK/Base"
end

# 全埋点
s.subspec 'AutoTrack' do |g|
g.ios.deployment_target = '9.0'
g.dependency 'SensorsAnalyticsSDK/Common'
s.subspec "AutoTrack" do |g|
g.ios.deployment_target = "9.0"
g.dependency "SensorsAnalyticsSDK/Common"
g.source_files = "SensorsAnalyticsSDK/AutoTrack/**/*.{h,m}"
g.public_header_files = 'SensorsAnalyticsSDK/AutoTrack/SensorsAnalyticsSDK+SAAutoTrack.h', 'SensorsAnalyticsSDK/AutoTrack/SAConfigOptions+AutoTrack.h'
g.frameworks = 'UIKit'
g.public_header_files = "SensorsAnalyticsSDK/AutoTrack/SensorsAnalyticsSDK+SAAutoTrack.h", "SensorsAnalyticsSDK/AutoTrack/SAConfigOptions+AutoTrack.h"
g.frameworks = "UIKit"
end

# 可视化相关功能,包含可视化全埋点和点击图
s.subspec 'Visualized' do |f|
f.ios.deployment_target = '9.0'
f.dependency 'SensorsAnalyticsSDK/AutoTrack'
# 可视化相关功能,包含可视化全埋点和点击图
s.subspec "Visualized" do |f|
f.ios.deployment_target = "9.0"
f.dependency "SensorsAnalyticsSDK/AutoTrack"
f.source_files = "SensorsAnalyticsSDK/Visualized/**/*.{h,m}"
f.public_header_files = 'SensorsAnalyticsSDK/Visualized/SensorsAnalyticsSDK+Visualized.h', 'SensorsAnalyticsSDK/Visualized/SAConfigOptions+Visualized.h'
f.public_header_files = "SensorsAnalyticsSDK/Visualized/SensorsAnalyticsSDK+Visualized.h", "SensorsAnalyticsSDK/Visualized/SAConfigOptions+Visualized.h"
end

# 开启 GPS 定位采集
s.subspec 'Location' do |f|
f.ios.deployment_target = '9.0'
f.frameworks = 'CoreLocation'
f.dependency 'SensorsAnalyticsSDK/Core'
s.subspec "Location" do |f|
f.ios.deployment_target = "9.0"
f.frameworks = "CoreLocation"
f.dependency "SensorsAnalyticsSDK/Core"
f.source_files = "SensorsAnalyticsSDK/Location/**/*.{h,m}"
f.public_header_files = 'SensorsAnalyticsSDK/Location/SensorsAnalyticsSDK+Location.h'
f.public_header_files = "SensorsAnalyticsSDK/Location/SensorsAnalyticsSDK+Location.h"
end

# 开启设备方向采集
s.subspec 'DeviceOrientation' do |f|
f.ios.deployment_target = '9.0'
f.dependency 'SensorsAnalyticsSDK/Core'
f.source_files = 'SensorsAnalyticsSDK/DeviceOrientation/**/*.{h,m}'
f.public_header_files = 'SensorsAnalyticsSDK/DeviceOrientation/SensorsAnalyticsSDK+DeviceOrientation.h'
f.frameworks = 'CoreMotion'
s.subspec "DeviceOrientation" do |f|
f.ios.deployment_target = "9.0"
f.dependency "SensorsAnalyticsSDK/Core"
f.source_files = "SensorsAnalyticsSDK/DeviceOrientation/**/*.{h,m}"
f.public_header_files = "SensorsAnalyticsSDK/DeviceOrientation/SensorsAnalyticsSDK+DeviceOrientation.h"
f.frameworks = "CoreMotion"
end

# 推送点击
s.subspec 'AppPush' do |f|
f.ios.deployment_target = '9.0'
f.dependency 'SensorsAnalyticsSDK/Core'
s.subspec "AppPush" do |f|
f.ios.deployment_target = "9.0"
f.dependency "SensorsAnalyticsSDK/Core"
f.source_files = "SensorsAnalyticsSDK/AppPush/**/*.{h,m}"
f.public_header_files = 'SensorsAnalyticsSDK/AppPush/SAConfigOptions+AppPush.h'
f.public_header_files = "SensorsAnalyticsSDK/AppPush/SAConfigOptions+AppPush.h"
end

# 使用崩溃事件采集
s.subspec 'Exception' do |e|
e.ios.deployment_target = '9.0'
e.dependency 'SensorsAnalyticsSDK/Common'
e.source_files = "SensorsAnalyticsSDK/Exception/**/*.{h,m}"
e.public_header_files = 'SensorsAnalyticsSDK/Exception/SAConfigOptions+Exception.h'
s.subspec "Exception" do |e|
e.ios.deployment_target = "9.0"
e.dependency "SensorsAnalyticsSDK/Common"
e.source_files = "SensorsAnalyticsSDK/Exception/**/*.{h,m}"
e.public_header_files = "SensorsAnalyticsSDK/Exception/SAConfigOptions+Exception.h"
end

# 基于 UA,使用 UIWebView 或者 WKWebView 进行打通
s.subspec 'WebView' do |w|
w.ios.deployment_target = '9.0'
w.dependency 'SensorsAnalyticsSDK/Core'
w.source_files = "SensorsAnalyticsSDK/WebView/**/*.{h,m}"
w.public_header_files = 'SensorsAnalyticsSDK/WebView/SensorsAnalyticsSDK+WebView.h'
s.subspec "WebView" do |w|
w.ios.deployment_target = "9.0"
w.dependency "SensorsAnalyticsSDK/Core"
w.source_files = "SensorsAnalyticsSDK/WebView/**/*.{h,m}"
w.public_header_files = "SensorsAnalyticsSDK/WebView/SensorsAnalyticsSDK+WebView.h"
end

# 基于 UA,使用 WKWebView 进行打通
s.subspec 'WKWebView' do |w|
w.ios.deployment_target = '9.0'
w.dependency 'SensorsAnalyticsSDK/Core'
w.source_files = "SensorsAnalyticsSDK/WKWebView/**/*.{h,m}"
w.public_header_files = 'SensorsAnalyticsSDK/WKWebView/SensorsAnalyticsSDK+WKWebView.h'
s.subspec "WKWebView" do |w|
w.ios.deployment_target = "9.0"
w.dependency "SensorsAnalyticsSDK/Core"
w.source_files = "SensorsAnalyticsSDK/WKWebView/**/*.{h,m}"
w.public_header_files = "SensorsAnalyticsSDK/WKWebView/SensorsAnalyticsSDK+WKWebView.h"
end

s.subspec 'ApplicationExtension' do |e|
e.dependency 'SensorsAnalyticsSDK/Extension'
e.source_files = 'SensorsAnalyticsSDK/AppExtension/*.{h,m}'
e.public_header_files = 'SensorsAnalyticsSDK/AppExtension/SensorsAnalyticsSDK+SAAppExtension.h'
s.subspec "ApplicationExtension" do |e|
e.dependency "SensorsAnalyticsSDK/Extension"
e.source_files = "SensorsAnalyticsSDK/AppExtension/*.{h,m}"
e.public_header_files = "SensorsAnalyticsSDK/AppExtension/SensorsAnalyticsSDK+SAAppExtension.h"
end

s.subspec 'DeprecatedCellClick' do |d|
d.ios.deployment_target = '9.0'
d.dependency 'SensorsAnalyticsSDK/Core'
d.source_files = 'CellClick_HookDelegate_Deprecated/*.{h,m}'
d.project_header_files = 'CellClick_HookDelegate_Deprecated/*.h'
s.subspec "DeprecatedCellClick" do |d|
d.ios.deployment_target = "9.0"
d.dependency "SensorsAnalyticsSDK/Core"
d.source_files = "CellClick_HookDelegate_Deprecated/*.{h,m}"
d.project_header_files = "CellClick_HookDelegate_Deprecated/*.h"
end

s.subspec 'Exposure' do |h|
h.ios.deployment_target = '9.0'
h.dependency 'SensorsAnalyticsSDK/Common'
h.source_files = 'SensorsAnalyticsSDK/Exposure/**/*.{h,m}'
h.public_header_files = 'SensorsAnalyticsSDK/Exposure/SAConfigOptions+Exposure.h', 'SensorsAnalyticsSDK/Exposure/SAExposureConfig.h', 'SensorsAnalyticsSDK/Exposure/SAExposureData.h', 'SensorsAnalyticsSDK/Exposure/SensorsAnalyticsSDK+Exposure.h', 'SensorsAnalyticsSDK/Exposure/UIView+ExposureIdentifier.h', 'SensorsAnalyticsSDK/Exposure/SAExposureListener.h'
s.subspec "Exposure" do |h|
h.ios.deployment_target = "9.0"
h.dependency "SensorsAnalyticsSDK/Common"
h.source_files = "SensorsAnalyticsSDK/Exposure/**/*.{h,m}"
h.public_header_files = "SensorsAnalyticsSDK/Exposure/SAConfigOptions+Exposure.h", "SensorsAnalyticsSDK/Exposure/SAExposureConfig.h", "SensorsAnalyticsSDK/Exposure/SAExposureData.h", "SensorsAnalyticsSDK/Exposure/SensorsAnalyticsSDK+Exposure.h", "SensorsAnalyticsSDK/Exposure/UIView+ExposureIdentifier.h", "SensorsAnalyticsSDK/Exposure/SAExposureListener.h"
end

s.frameworks = "Foundation"
s.libraries = "icucore", "z"
end
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ @implementation SAEventLibObject
- (instancetype)init {
self = [super init];
if (self) {
#if TARGET_OS_IOS
#if TARGET_OS_IOS || TARGET_OS_WATCH
// FIXME: If supported, report "watchOS".
_lib = @"iOS";
#elif TARGET_OS_OSX
_lib = @"macOS";
Expand Down
25 changes: 19 additions & 6 deletions SensorsAnalyticsSDK/Core/Builder/SAIdentifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@
#import "SensorsAnalyticsSDK+Private.h"
#import "SALimitKeyManager.h"

#if TARGET_OS_IOS
#if TARGET_OS_IOS || TARGET_OS_WATCH
#import "SAKeyChainItemWrapper.h"
#endif

#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#elif TARGET_OS_WATCH
#import <WatchKit/WatchKit.h>
#endif

NSString * const kSAIdentities = @"com.sensorsdata.identities";
Expand Down Expand Up @@ -122,7 +127,7 @@ - (BOOL)identify:(NSString *)anonymousId {

- (void)archiveAnonymousId:(NSString *)anonymousId {
[[SAStoreManager sharedInstance] setObject:anonymousId forKey:kSAEventDistinctId];
#if TARGET_OS_IOS
#if TARGET_OS_IOS || TARGET_OS_WATCH
[SAKeyChainItemWrapper saveUdid:anonymousId];
#endif
}
Expand Down Expand Up @@ -226,7 +231,7 @@ - (void)clearLoginInfo {
});
}

#if TARGET_OS_IOS
#if TARGET_OS_IOS || TARGET_OS_WATCH
+ (NSString *)idfa {
NSString *idfa = SALimitKeyManager.idfa;
if ([idfa isEqualToString:@""]) {
Expand All @@ -235,6 +240,9 @@ + (NSString *)idfa {
return idfa;
}

#if TARGET_OS_WATCH
return nil;
#else
Class cla = NSClassFromString(@"SAIDFAHelper");
SEL sel = NSSelectorFromString(@"idfa");
if ([cla respondsToSelector:sel]) {
Expand All @@ -244,6 +252,7 @@ + (NSString *)idfa {
}
}
return nil;
#endif
}

+ (NSString *)idfv {
Expand All @@ -254,7 +263,11 @@ + (NSString *)idfv {
return idfv;
}

#if TARGET_OS_IOS
return [UIDevice currentDevice].identifierForVendor.UUIDString;
#elif TARGET_OS_WATCH
return [WKInterfaceDevice currentDevice].identifierForVendor.UUIDString;
#endif
}
#elif TARGET_OS_OSX
/// mac SerialNumber(序列号)作为设备标识
Expand All @@ -277,7 +290,7 @@ + (NSString *)serialNumber {

+ (NSString *)hardwareID {
NSString *distinctId = nil;
#if TARGET_OS_IOS
#if TARGET_OS_IOS || TARGET_OS_WATCH
distinctId = [self idfa];
// 没有IDFA,则使用IDFV
if (!distinctId) {
Expand All @@ -300,7 +313,7 @@ + (NSString *)hardwareID {
- (NSString *)unarchiveAnonymousId {
NSString *anonymousId = [[SAStoreManager sharedInstance] objectForKey:kSAEventDistinctId];

#if TARGET_OS_IOS
#if TARGET_OS_IOS || TARGET_OS_WATCH
NSString *distinctIdInKeychain = [SAKeyChainItemWrapper saUdid];
if (distinctIdInKeychain.length > 0) {
if (![anonymousId isEqualToString:distinctIdInKeychain]) {
Expand Down Expand Up @@ -588,7 +601,7 @@ - (NSDictionary *)unarchiveIdentitiesWithKey:(NSString *)loginIDKey {
if (!identities[kSAIdentitiesUniqueID] && !identities[kSAIdentitiesUUID] ) {
NSString *key = kSAIdentitiesUUID;
NSString *value = [NSUUID UUID].UUIDString;
#if TARGET_OS_IOS
#if TARGET_OS_IOS || TARGET_OS_WATCH
if ([SAIdentifier idfv]) {
key = kSAIdentitiesUniqueID;
value = [SAIdentifier idfv];
Expand Down
6 changes: 6 additions & 0 deletions SensorsAnalyticsSDK/Core/Builder/SAPresetPropertyObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ NS_ASSUME_NONNULL_BEGIN
@end
#endif

#if TARGET_OS_WATCH
@interface SAWatchPresetProperty : SAPresetPropertyObject

@end
#endif

NS_ASSUME_NONNULL_END
Loading