Skip to content

Commit

Permalink
Release 1.6.17
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhzh committed Oct 10, 2016
1 parent 3a5eb07 commit 6159f3a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK/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 = "1.6.16"
s.version = "1.6.17"
s.summary = "The offical 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ - (NSArray *) getFirstRecords:(NSUInteger)recordSize withType:(NSString *)type {
int rc = sqlite3_prepare_v2(_database, [query UTF8String], -1, &stmt, NULL);
if(rc == SQLITE_OK) {
while (sqlite3_step(stmt) == SQLITE_ROW) {
NSString *content =[NSString stringWithUTF8String:(char*)sqlite3_column_text(stmt, 0)];
[contentArray addObject:content];
char *ch = (char*)sqlite3_column_text(stmt, 0);
if (ch) {
NSString *content =[NSString stringWithUTF8String:ch];
if (content) {
[contentArray addObject:content];
}
}
}
sqlite3_finalize(stmt);
}
Expand Down
15 changes: 15 additions & 0 deletions SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,21 @@ typedef NS_ENUM(NSInteger, SensorsAnalyticsAppPushService) {
*/
- (BOOL)showUpWebView:(id)webView WithRequest:(NSURLRequest *)request;

/**
* @abstract
* 将distinctId传递给当前的WebView
*
* @discussion
* 混合开发时,将distinctId传递给当前的WebView
*
* @param webView 当前WebView,支持<code>UIWebView</code>和<code>WKWebView</code>
* @param request NSURLRequest
* @param propertyDict NSDictionary 自定义扩展属性
*
* @return YES:SDK已进行处理,NO:SDK没有进行处理
*/
- (BOOL)showUpWebView:(id)webView WithRequest:(NSURLRequest *)request andProperties:(NSDictionary *)propertyDict;

/**
* @property
*
Expand Down
39 changes: 29 additions & 10 deletions SensorsAnalyticsSDK/SensorsAnalyticsSDK/SensorsAnalyticsSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#import <WebKit/WebKit.h>
#endif

#define VERSION @"1.6.16"
#define VERSION @"1.6.17"

#define PROPERTY_LENGTH_LIMITATION 8191

Expand Down Expand Up @@ -297,6 +297,10 @@ - (void)enableEditingVTrack {
}

- (BOOL)showUpWebView:(id)webView WithRequest:(NSURLRequest *)request {
return [self showUpWebView:webView WithRequest:request andProperties:nil];
}

- (BOOL)showUpWebView:(id)webView WithRequest:(NSURLRequest *)request andProperties:(NSDictionary *)propertyDict {
SADebug(@"showUpWebView");
if (webView == nil) {
SADebug(@"showUpWebView == nil");
Expand All @@ -308,8 +312,21 @@ - (BOOL)showUpWebView:(id)webView WithRequest:(NSURLRequest *)request {
return NO;
}

JSONUtil *_jsonUtil = [[JSONUtil alloc] init];

NSDictionary *bridgeCallbackInfo = [self webViewJavascriptBridgeCallbackInfo];
NSMutableDictionary *properties = [[NSMutableDictionary alloc] init];
if (bridgeCallbackInfo) {
[properties addEntriesFromDictionary:bridgeCallbackInfo];
}
if (propertyDict) {
[properties addEntriesFromDictionary:propertyDict];
}
NSData* jsonData = [_jsonUtil JSONSerializeObject:properties];
NSString* jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

NSString *scheme = @"sensorsanalytics://getAppInfo";
NSString *js = [NSString stringWithFormat:@"sensorsdata_app_js_bridge_call_js('%@')", [self webViewJavascriptBridgeCallbackInfo]];
NSString *js = [NSString stringWithFormat:@"sensorsdata_app_js_bridge_call_js('%@')", jsonString];
if ([webView isKindOfClass:[UIWebView class]] == YES) {//UIWebView
SADebug(@"showUpWebView: UIWebView");
if ([request.URL.absoluteString rangeOfString:scheme].location != NSNotFound) {
Expand All @@ -336,18 +353,16 @@ - (BOOL)showUpWebView:(id)webView WithRequest:(NSURLRequest *)request {
}
}

- (NSString *)webViewJavascriptBridgeCallbackInfo {
JSONUtil *_jsonUtil = [[JSONUtil alloc] init];
- (NSMutableDictionary *)webViewJavascriptBridgeCallbackInfo {
NSMutableDictionary *libProperties = [[NSMutableDictionary alloc] init];
[libProperties setValue:@"iOS" forKey:@"type"];
[libProperties setValue:[self distinctId] forKey:@"distinct_id"];
NSData* jsonData = [_jsonUtil JSONSerializeObject:libProperties];
NSString* jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
return [jsonString copy];
return [libProperties copy];
}

- (void)enableAutoTrack {
_autoTrack = YES;
[self _enableAutoTrack];
}

- (void)flushByType:(NSString *)type withSize:(int)flushSize andFlushMethod:(BOOL (^)(NSArray *))flushMethod {
Expand Down Expand Up @@ -1336,6 +1351,10 @@ - (void)setUpListeners {
name:UIApplicationDidEnterBackgroundNotification
object:nil];

[self _enableAutoTrack];
}

- (void)_enableAutoTrack {
void (^block)(id, SEL, id) = ^(id obj, SEL sel, NSNumber* a) {
if (_autoTrack) {
UIViewController *controller = (UIViewController *)obj;
Expand All @@ -1347,7 +1366,7 @@ - (void)setUpListeners {
if (!klass) {
return;
}

NSString *screenName = NSStringFromClass(klass);
if ([screenName isEqualToString:@"SFBrowserRemoteViewController"] ||
[screenName isEqualToString:@"SFSafariViewController"] ||
Expand Down Expand Up @@ -1378,11 +1397,11 @@ - (void)setUpListeners {
[properties addEntriesFromDictionary:[autoTrackerController getTrackProperties]];
_lastScreenTrackProperties = [autoTrackerController getTrackProperties];
}

if ([controller conformsToProtocol:@protocol(SAScreenAutoTracker)]) {
UIViewController<SAScreenAutoTracker> *screenAutoTrackerController = (UIViewController<SAScreenAutoTracker> *)controller;
NSString *currentScreenUrl = [screenAutoTrackerController getScreenUrl];

[properties setValue:currentScreenUrl forKey:SCREEN_URL_PROPERTY];
@synchronized(_referrerScreenUrl) {
if (_referrerScreenUrl) {
Expand Down

0 comments on commit 6159f3a

Please sign in to comment.