Skip to content

Commit

Permalink
Release 1.3.7
Browse files Browse the repository at this point in the history
1. 优化可视化埋点通信协议
  • Loading branch information
Yuhan ZOU committed Mar 23, 2016
1 parent aeb50f6 commit 73b5bc5
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 116 deletions.
6 changes: 3 additions & 3 deletions SensorsAnalyticsSDK/HelloSensorsAnalytics/DemoController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ - (void)didReceiveMemoryWarning {
}

- (void)testInit {
[SensorsAnalyticsSDK sharedInstanceWithServerURL:@"http://{sa_host}:8006/sa?token={token}"
andConfigureURL:@"http://{sa_host}:8007/api/vtrack/config"
andDebugMode:SensorsAnalyticsDebugOff];
[SensorsAnalyticsSDK sharedInstanceWithServerURL:@"http://${service_name}.cloud.sensorsdata.cn:8006/sa?token=${token}"
andConfigureURL:@"http://${service_name}.cloud.sensorsdata.cn/api/vtrack/config/"
andDebugMode:SensorsAnalyticsDebugAndTrack];
}

- (void)testTrack {
Expand Down
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.3.5"
s.version = "1.3.6"
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 @@ -587,7 +587,7 @@
INFOPLIST_FILE = HelloSensorsAnalytics/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.sensorsdata.sdk.HelloSensorsAnalytics;
PRODUCT_BUNDLE_IDENTIFIER = com.sensorsdata.sdk;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -602,7 +602,7 @@
INFOPLIST_FILE = HelloSensorsAnalytics/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.sensorsdata.sdk.HelloSensorsAnalytics;
PRODUCT_BUNDLE_IDENTIFIER = com.sensorsdata.sdk;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
- (id)payloadObjectForKey:(NSString *)key;
- (NSDictionary *)payload;

- (NSData *)JSONData;
- (NSData *)JSONData:(BOOL)useGzip;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/// Copyright (c) 2014 Mixpanel. All rights reserved.
//

#import "LFCGzipUtility.h"
#import "NSData+SABase64.h"
#import "SAAbstractDesignerMessage.h"
#import "SALogger.h"

Expand Down Expand Up @@ -52,8 +54,29 @@ - (NSDictionary *)payload {
return [_payload copy];
}

- (NSData *)JSONData {
NSDictionary *jsonObject = @{ @"type" : _type, @"payload" : [_payload copy] };
- (NSData *)JSONData:(BOOL)useGzip {
NSMutableDictionary *jsonObject = [[NSMutableDictionary alloc] init];

[jsonObject setObject:_type forKey:@"type"];

if (useGzip) {
// 如果使用 GZip 压缩
NSError *error = nil;

// 1. 序列化 Payload
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[_payload copy] options:0 error:&error];
NSString * jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

// 2. 使用 GZip 进行压缩
NSData *zippedData = [LFCGzipUtility gzipData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];

// 3. Base64 Encode
NSString *b64String = [zippedData sa_base64EncodedString];

[jsonObject setValue:b64String forKey:@"gzip_payload"];
} else {
[jsonObject setValue:[_payload copy] forKey:@"payload"];
}

NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:0 error:&error];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

@property (nonatomic, readonly) BOOL connected;
@property (nonatomic, assign) BOOL sessionEnded;
@property (nonatomic, assign) BOOL useGzip;

- (instancetype)initWithURL:(NSURL *)url;
- (instancetype)initWithURL:(NSURL *)url keepTrying:(BOOL)keepTrying connectCallback:(void (^)())connectCallback disconnectCallback:(void (^)())disconnectCallback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ - (instancetype)initWithURL:(NSURL *)url
_open = NO;
_connected = NO;
_sessionEnded = NO;
_useGzip = NO;
_session = [[NSMutableDictionary alloc] init];
_url = url;
_connectCallback = connectCallback;
Expand Down Expand Up @@ -147,7 +148,8 @@ - (id)sessionObjectForKey:(NSString *)key {

- (void)sendMessage:(id<SADesignerMessage>)message {
if (_connected) {
NSString *jsonString = [[NSString alloc] initWithData:[message JSONData] encoding:NSUTF8StringEncoding];

NSString *jsonString = [[NSString alloc] initWithData:[message JSONData:_useGzip] encoding:NSUTF8StringEncoding];
SADebug(@"%@ VTrack sending message: %@", self, [message description]);
[_webSocket send:jsonString];
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ - (NSOperation *)responseCommandWithConnection:(SADesignerConnection *)connectio
SADesignerDeviceInfoResponseMessage *deviceInfoResponseMessage = [SADesignerDeviceInfoResponseMessage message];

dispatch_sync(dispatch_get_main_queue(), ^{
// 服务端是否支持 Payload 压缩
id supportGzip = [self payloadObjectForKey:@"support_gzip"];
conn.useGzip = (supportGzip == nil) ? NO : [supportGzip boolValue];

UIDevice *currentDevice = [UIDevice currentDevice];
struct CGSize size = [UIScreen mainScreen].bounds.size;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ extern NSString *const SADesignerEventBindingRequestMessageType;

@interface SADesignerTrackMessage : SAAbstractDesignerMessage

+ (instancetype)message;
+ (instancetype)messageWithPayload:(NSDictionary *)payload;

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,8 @@ @implementation SADesignerTrackMessage {
NSDictionary *_payload;
}

+ (instancetype)message {
return [[self alloc] initWithType:@"debug_track" andPayload:@{}];
}

+ (instancetype)messageWithPayload:(NSDictionary *)payload {
return[[self alloc] initWithType:@"debug_track" andPayload:payload];
}

- (instancetype)initWithType:(NSString *)type andPayload:(NSDictionary *)payload {
if (self = [super initWithType:type]) {
_payload = payload;
}
return self;
}

- (NSData *)JSONData {
NSDictionary *jsonObject = @{ @"type" : self.type, @"payload" : [_payload copy] };

NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:0 error:&error];
if (error) {
NSLog(@"Failed to serialize test designer message: %@", error);
}

return jsonData;
return[[self alloc] initWithType:@"debug_track" payload:payload];
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- (void)setPayloadObject:(id)object forKey:(NSString *)key;
- (id)payloadObjectForKey:(NSString *)key;

- (NSData *)JSONData;
- (NSData *)JSONData:(BOOL)useGzip;

- (NSOperation *)responseCommandWithConnection:(SADesignerConnection *)connection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ + (instancetype)message {
}

- (SAObjectSerializerConfig *)configuration {
NSDictionary *config =
[self payloadObjectForKey:@"config"];
NSDictionary *config = [self payloadObjectForKey:@"config"];
return config ? [[SAObjectSerializerConfig alloc] initWithDictionary:config] : nil;
}

Expand Down
Loading

0 comments on commit 73b5bc5

Please sign in to comment.