diff --git a/SensorsAnalyticsSDK/SensorsAnalyticsSDK.podspec b/SensorsAnalyticsSDK/SensorsAnalyticsSDK.podspec
index 52d83c73..b48d74e9 100644
--- a/SensorsAnalyticsSDK/SensorsAnalyticsSDK.podspec
+++ b/SensorsAnalyticsSDK/SensorsAnalyticsSDK.podspec
@@ -1,137 +1,16 @@
-#
-# Be sure to run `pod spec lint SensorsAnalyticsSDK.podspec' to ensure this is a
-# valid spec and to remove all comments including this before submitting the spec.
-#
-# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
-# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
-#
-
Pod::Spec.new do |s|
-
- # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
- #
- # These will help people to find your library, and whilst it
- # can feel like a chore to fill in it's definitely to your advantage. The
- # summary should be tweet-length, and the description more in depth.
- #
-
s.name = "SensorsAnalyticsSDK"
- s.version = "1.2.1"
- s.summary = "iOS SDK of SensorsAnalytics."
-
- # This description is used to generate tags and improve search results.
- # * Think: What does it do? Why did you write it? What is the focus?
- # * Try to keep it short, snappy and to the point.
- # * Write the description between the DESC delimiters below.
- # * Finally, don't worry about the indent, CocoaPods strips it!
- s.description = <<-DESC
- DESC
-
+ s.version = "1.3.1"
+ s.summary = "The offical iOS SDK of Sensors Analytics."
s.homepage = "http://www.sensorsdata.cn"
- # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
-
-
- # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
- #
- # Licensing your code is important. See http://choosealicense.com for more info.
- # CocoaPods will detect a license file if there is a named LICENSE*
- # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
- #
-
- s.license = "MIT (example)"
- # s.license = { :type => "MIT", :file => "FILE_LICENSE" }
-
-
- # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
- #
- # Specify the authors of the library, with email addresses. Email addresses
- # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
- # accepts just a name if you'd rather not provide an email address.
- #
- # Specify a social_media_url where others can refer to, for example a twitter
- # profile URL.
- #
-
- s.author = { "Yuhan ZOU" => "zouyuhan@sensorsdata.cn" }
- # Or just: s.author = "Yuhan ZOU"
- # s.authors = { "Yuhan ZOU" => "zouyuhan@sensorsdata.cn" }
- # s.social_media_url = "http://twitter.com/Yuhan ZOU"
-
- # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
- #
- # If this Pod runs only on iOS or OS X, then specify the platform and
- # the deployment target. You can optionally include the target after the platform.
- #
-
- s.platform = :ios
- s.platform = :ios, "5.0"
-
- # When using multiple platforms
- # s.ios.deployment_target = "5.0"
- # s.osx.deployment_target = "10.7"
- # s.watchos.deployment_target = "2.0"
- # s.tvos.deployment_target = "9.0"
-
-
- # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
- #
- # Specify the location from where the source should be retrieved.
- # Supports git, hg, bzr, svn and HTTP.
- #
-
- s.source = { :git => "http://EXAMPLE/SensorsAnalyticsSDK.git", :tag => "0.0.1" }
-
-
- # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
- #
- # CocoaPods is smart about how it includes source code. For source files
- # giving a folder will include any swift, h, m, mm, c & cpp files.
- # For header files it will include any header in the folder.
- # Not including the public_header_files will make all headers public.
- #
-
- s.source_files = "Classes", "Classes/**/*.{h,m}"
- s.exclude_files = "Classes/Exclude"
-
- # s.public_header_files = "Classes/**/*.h"
-
-
- # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
- #
- # A list of resources included with the Pod. These are copied into the
- # target bundle with a build phase script. Anything else will be cleaned.
- # You can preserve files from being cleaned, please don't preserve
- # non-essential files like tests, examples and documentation.
- #
-
- # s.resource = "icon.png"
- # s.resources = "Resources/*.png"
-
- # s.preserve_paths = "FilesToSave", "MoreFilesToSave"
-
-
- # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
- #
- # Link your library with frameworks, or libraries. Libraries do not include
- # the lib prefix of their name.
- #
-
- # s.framework = "SomeFramework"
- # s.frameworks = "SomeFramework", "AnotherFramework"
-
- # s.library = "iconv"
- # s.libraries = "iconv", "xml2"
-
-
- # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
- #
- # If your library depends on compiler flags you can set them in the xcconfig hash
- # where they will only apply to your library. If you depend on other Podspecs
- # you can include multiple dependencies to ensure it works.
-
- # s.requires_arc = true
-
- # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
- # s.dependency "JSONKit", "~> 1.4"
+ 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" => "zouyuhan@sensorsdata.cn" }
+
+ s.source_files = "SensorsAnalyticsSDK/SensorsAnalyticsSDK", "SensorsAnalyticsSDK/SensorsAnalyticsSDK/*.{h,m}"
+ s.public_header_files = "SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h"
+ s.frameworks = 'UIKit', 'Foundation', 'SystemConfiguration', 'CoreTelephony', 'CoreGraphics', 'QuartzCore'
+ s.libraries = 'icucore', 'sqlite3', 'z'
+ s.platform = :ios, "8.0"
end
diff --git a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h
index 6a00d03e..4954a7ac 100755
--- a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h
+++ b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h
@@ -117,7 +117,10 @@ typedef NS_ENUM(NSInteger, SensorsAnalyticsDebugMode) {
/**
* @abstract
- * 根据传入的所部署的SensorsAnalytics服务器的URL,返回一个SensorsAnalyticsSDK
的单例
+ * 根据传入的所部署的 Sensors Analytics 服务器的URL,返回一个SensorsAnalyticsSDK
的单例
+ *
+ * @discussion
+ * 若不需要可视化埋点功能,则 configureURL 和 vtrackServerURL 参数传入 nil 即可。
*
* @param serverURL 收集事件的URL
* @param configureURL 获取配置信息的URL
diff --git a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m
index af3c8b8d..646097b2 100755
--- a/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m
+++ b/SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m
@@ -26,7 +26,7 @@
#import "SASwizzler.h"
#import "SensorsAnalyticsSDK.h"
-#define VERSION @"1.3.0"
+#define VERSION @"1.3.1"
@implementation SensorsAnalyticsDebugException
@@ -119,20 +119,19 @@ - (instancetype)initWithServerURL:(NSString *)serverURL
andConfigureURL:(NSString *)configureURL
andVTrackServerURL:(NSString *)vtrackServerURL
andDebugMode:(SensorsAnalyticsDebugMode)debugMode {
- if (serverURL == nil || [serverURL length] == 0
- || configureURL == nil || [configureURL length] == 0
- || vtrackServerURL == nil || [vtrackServerURL length] == 0) {
+ if (serverURL == nil || [serverURL length] == 0) {
@throw [NSException exceptionWithName:@"InvalidArgumentException"
reason:@"serverURL, configureURL or vtrackServerURL is nil"
userInfo:nil];
}
if (debugMode != SensorsAnalyticsDebugOff) {
- if ([serverURL length] < [@"debug" length] || ![serverURL hasSuffix:@"debug"]) {
- NSString *errMsg = [NSString stringWithFormat:@"The server url of SensorsAnalytics must ends with 'debug' while DEBUG mode is defined. [url='%@' expected_url='http://example.com/debug']", serverURL];
+ NSURL *serverUrl = [NSURL URLWithString:serverURL];
+ if ([serverUrl.path length] < [@"debug" length] || ![serverUrl.path hasSuffix:@"debug"]) {
+ NSString *errMsg = [NSString stringWithFormat:@"The server url of SensorsAnalytics must ends with 'debug' while DEBUG mode is defined. [url='%@' expected_url='http://example.com/debug?token=xxx']", serverURL];
@throw [SensorsAnalyticsDebugException exceptionWithName:@"InvalidArgumentException"
- reason:errMsg
- userInfo:nil];
+ reason:errMsg
+ userInfo:nil];
}
}
@@ -191,7 +190,12 @@ - (instancetype)initWithServerURL:(NSString *)serverURL
}
- (void)flush {
- NSArray * recordArray = [self.messageQueue getFirstRecords:50];
+ int flushSize = 50;
+ if (_debugMode != SensorsAnalyticsDebugOff) {
+ flushSize = 1;
+ }
+
+ NSArray *recordArray = [self.messageQueue getFirstRecords:flushSize];
if (recordArray == nil) {
@throw [NSException exceptionWithName:@"SqliteException"
reason:@"getFirstRecords from Message Queue in Sqlite fail"
@@ -219,7 +223,7 @@ - (void)flush {
[request setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
[request setValue:@"SensorsAnalytics iOS SDK" forHTTPHeaderField:@"User-Agent"];
if (_debugMode == SensorsAnalyticsDebugOnly) {
- [request setValue:@"true" forKey:@"Dry-Run"];
+ [request setValue:@"true" forHTTPHeaderField:@"Dry-Run"];
}
NSError *error = nil;
@@ -243,11 +247,12 @@ - (void)flush {
NSString *urlResponseContent = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSString *errMsg = [NSString stringWithFormat:@"%@ flush failure with response '%@'.", self, urlResponseContent];
if (_debugMode != SensorsAnalyticsDebugOff) {
+ SALog(@"==========================================================================");
SALog(@"%@ invalid message: %@", self, jsonString);
SALog(@"%@ ret_code: %ld", self, [urlResponse statusCode]);
SALog(@"%@ ret_content: %@", self, urlResponseContent);
- @throw [SensorsAnalyticsDebugException exceptionWithName:@"NetworkException"
+ @throw [SensorsAnalyticsDebugException exceptionWithName:@"IllegalDataException"
reason:errMsg
userInfo:nil];
} else {
@@ -256,16 +261,17 @@ - (void)flush {
}
} else {
if (_debugMode != SensorsAnalyticsDebugOff) {
+ SALog(@"==========================================================================");
SALog(@"%@ valid message: %@", self, jsonString);
}
}
- if (![self.messageQueue removeFirstRecords:50]) {
+ if (![self.messageQueue removeFirstRecords:flushSize]) {
@throw [NSException exceptionWithName:@"SqliteException"
reason:@"removeFirstRecords from Message Queue in Sqlite fail"
userInfo:nil];
}
- recordArray = [self.messageQueue getFirstRecords:50];
+ recordArray = [self.messageQueue getFirstRecords:flushSize];
if (recordArray == nil) {
@throw [NSException exceptionWithName:@"SqliteException"
reason:@"getFirstRecords from Message Queue in Sqlite fail"
@@ -846,6 +852,10 @@ - (void)checkForConfigure {
dispatch_async(self.serialQueue, ^{
SADebug(@"%@ starting configure check", self);
+ if (self.configureURL == nil || self.configureURL.length < 1) {
+ return;
+ }
+
NSURL *URL = [NSURL URLWithString:self.configureURL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
[request setHTTPMethod:@"GET"];
@@ -896,6 +906,10 @@ - (void)connectToVTrackDesigner {
}
- (void)connectToVTrackDesigner:(BOOL)reconnect {
+ if (self.vtrackServerURL == nil || self.vtrackServerURL.length < 1) {
+ return;
+ }
+
if ([self.abtestDesignerConnection isKindOfClass:[SADesignerConnection class]]
&& ((SADesignerConnection *)self.abtestDesignerConnection).connected) {
SALog(@"A/B test designer connection already exists");