Skip to content

Commit

Permalink
feat: Configuration 增加 EncryptEnabled 配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
YoloMao committed Nov 9, 2021
1 parent 0e4ebf6 commit 1f90d5e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion GrowingAnalytics.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'GrowingAnalytics'
s.version = '3.3.1'
s.version = '3.3.1-hotfix.1'
s.summary = 'iOS SDK of GrowingIO.'
s.description = <<-DESC
GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和行为数据等。目前支持代码埋点、无埋点、可视化圈选、热图等功能。
Expand Down Expand Up @@ -107,6 +107,7 @@ GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和
config.pod_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => 'GROWING_ANALYSIS_DISABLE_IDFA=1'}
end

# deprecated
s.subspec 'ENABLE_ENCRYPTION' do |config|
config.dependency 'GrowingAnalytics/TrackerCore'
config.pod_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => 'GROWING_ANALYSIS_ENABLE_ENCRYPTION=1'}
Expand Down
12 changes: 11 additions & 1 deletion GrowingTrackerCore/GrowingRealTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#import "GrowingModuleManager.h"
#import "GrowingEventManager.h"

NSString *const GrowingTrackerVersionName = @"3.3.1";
NSString *const GrowingTrackerVersionName = @"3.3.1-hotfix.1";
const int GrowingTrackerVersionCode = 30301;

@interface GrowingRealTracker ()
Expand Down Expand Up @@ -103,6 +103,16 @@ - (GrowingLogLevel)logLevel {
- (void)versionPrint {
NSString *versionStr = [NSString stringWithFormat:@"Thank you very much for using GrowingIO. We will do our best to provide you with the best service. GrowingIO version: %@",GrowingTrackerVersionName];
GIOLogInfo(@"%@", versionStr);

#ifdef GROWING_ANALYSIS_ENABLE_ENCRYPTION
GIOLogWarn(@"\n"
@"╔═══════════════════════════════════════════════════════════════════════════════════════\n"
@"\n"
@"║ WARNING: pod ENABLE_ENCRYPTION is deprecated, please use -[GrowingTrackConfiguration setEncryptEnabled]\n"
@"║ 警告: pod ENABLE_ENCRYPTION 已被废弃, 请使用 -[GrowingTrackConfiguration setEncryptEnabled] 进行配置\n"
@"\n"
@"╚═══════════════════════════════════════════════════════════════════════════════════════");
#endif
}

+ (NSString *)versionName {
Expand Down
1 change: 1 addition & 0 deletions GrowingTrackerCore/GrowingTrackConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ FOUNDATION_EXPORT NSString * const kGrowingDefaultDataCollectionServerHost;
@property (nonatomic, assign) NSUInteger ignoreField;
@property (nonatomic, assign) BOOL idMappingEnabled;
@property (nonatomic, copy) NSString *urlScheme;
@property (nonatomic, assign) BOOL encryptEnabled;

- (instancetype)initWithProjectId:(NSString *)projectId;

Expand Down
2 changes: 2 additions & 0 deletions GrowingTrackerCore/GrowingTrackConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ - (instancetype)initWithProjectId:(NSString *)projectId {
_ignoreField = 0;
_idMappingEnabled = NO;
_urlScheme = nil;
_encryptEnabled = NO;
}

return self;
Expand All @@ -63,6 +64,7 @@ - (id)copyWithZone:(NSZone *)zone {
configuration->_ignoreField = _ignoreField;
configuration->_idMappingEnabled = _idMappingEnabled;
configuration->_urlScheme = _urlScheme;
configuration->_encryptEnabled = _encryptEnabled;
return configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#import "GrowingEventRequestAdapter.h"
#import "GrowingEventRequest.h"
#import "NSData+GrowingHelper.h"
#import "GrowingTimeUtil.h"
#import "GrowingConfigurationManager.h"
#import "GrowingLogger.h"

@implementation GrowingEventRequestHeaderAdapter

- (NSMutableURLRequest *)adaptedRequest:(NSMutableURLRequest *)request {

NSMutableURLRequest *needAdaptReq = request;
#ifdef GROWING_ANALYSIS_ENABLE_ENCRYPTION
// deprecated
[needAdaptReq setValue:@"3" forHTTPHeaderField:@"X-Compress-Codec"];
[needAdaptReq setValue:@"1" forHTTPHeaderField:@"X-Crypt-Codec"];
#else
BOOL encryptEnabled = GrowingConfigurationManager.sharedInstance.trackConfiguration.encryptEnabled;
if (encryptEnabled) {
[needAdaptReq setValue:@"3" forHTTPHeaderField:@"X-Compress-Codec"];
[needAdaptReq setValue:@"1" forHTTPHeaderField:@"X-Crypt-Codec"];
}
#endif
[needAdaptReq setValue:[NSString stringWithFormat:@"%lld",[GrowingTimeUtil currentTimeMillis]] forHTTPHeaderField:@"X-Timestamp"];
[needAdaptReq setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
Expand Down Expand Up @@ -71,8 +78,15 @@ - (NSMutableURLRequest *)adaptedRequest:(NSMutableURLRequest *)request {
NSString *jsonString = [self buildJSONStringWithEvents:self.events];
JSONData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
#ifdef GROWING_ANALYSIS_ENABLE_ENCRYPTION
// deprecated
JSONData = [JSONData growingHelper_LZ4String];
JSONData = [JSONData growingHelper_xorEncryptWithHint:(self.timestamp & 0xFF)];
#else
BOOL encryptEnabled = GrowingConfigurationManager.sharedInstance.trackConfiguration.encryptEnabled;
if (encryptEnabled) {
JSONData = [JSONData growingHelper_LZ4String];
JSONData = [JSONData growingHelper_xorEncryptWithHint:(self.timestamp & 0xFF)];
}
#endif
}
if (self.outsizeBlock) {
Expand Down

0 comments on commit 1f90d5e

Please sign in to comment.