Commit 6f16a068 authored by 汪洋's avatar 汪洋

Merge branch 'jql/201' into 'master'

埋点库修改参数为空问题

See merge request !49
parents 1b3dbcc9 b8825c07
...@@ -37,7 +37,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -37,7 +37,7 @@ NSString *const MockCityId = @"beijing";
#else #else
NSString *url = @"http://log.test.igengmei.com/log/collect"; NSString *url = @"http://log.test.igengmei.com/log/collect";
#endif #endif
// [[NSUserDefaults standardUserDefaults] setBool:YES forKey:PhobosGray]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:PhobosGray];
Phobos *client = [Phobos clientWithAppName:MockAppName channelId:MockChannelId]; Phobos *client = [Phobos clientWithAppName:MockAppName channelId:MockChannelId];
[Phobos setSharedClient:client]; [Phobos setSharedClient:client];
Phobos.sharedClient.serverAPI = url; Phobos.sharedClient.serverAPI = url;
...@@ -75,10 +75,10 @@ NSString *const MockCityId = @"beijing"; ...@@ -75,10 +75,10 @@ NSString *const MockCityId = @"beijing";
[Phobos track:@"test2" attributes:dict sendNow:YES]; [Phobos track:@"test2" attributes:dict sendNow:YES];
[Phobos track:@"test3" attributes:dict sendNow:YES]; [Phobos track:@"test3" attributes:dict sendNow:YES];
[Phobos track:@"test4" attributes:dict sendNow:YES]; [Phobos track:@"test4" attributes:dict sendNow:YES];
[Phobos track:@"test3" attributes:dict sendNow:YES]; [Phobos track:@"test5" attributes:dict sendNow:YES];
[Phobos track:@"test4" attributes:dict sendNow:YES]; [Phobos track:@"test6" attributes:dict sendNow:YES];
[Phobos track:@"test3" attributes:dict sendNow:YES]; [Phobos track:@"test7" attributes:dict sendNow:YES];
[Phobos track:@"test4" attributes:dict sendNow:YES]; [Phobos track:@"test8" attributes:dict sendNow:YES];
// array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey]; // array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
} }
......
...@@ -137,7 +137,6 @@ NSString *const MockCityId = @"beijing"; ...@@ -137,7 +137,6 @@ NSString *const MockCityId = @"beijing";
// 因为实时埋点是异步删除,所以这个位置暂时延时取数据,待优化 TODO // 因为实时埋点是异步删除,所以这个位置暂时延时取数据,待优化 TODO
XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 0, @"array shouldn't be empty"); XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 0, @"array shouldn't be empty");
XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 0, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:attr sendNow:YES]; [Phobos track:MockEventId attributes:attr sendNow:YES];
XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 0, @"array shouldn't be empty"); XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 0, @"array shouldn't be empty");
...@@ -268,6 +267,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -268,6 +267,7 @@ NSString *const MockCityId = @"beijing";
// 某种情况下没有先走 onPageStart,只走了OnPageEnd,此时数据应该完整,某个key对应的value可以是空 // 某种情况下没有先走 onPageStart,只走了OnPageEnd,此时数据应该完整,某个key对应的value可以是空
- (void)testOnPageEnd { - (void)testOnPageEnd {
GMPhobosController *controller = [GMPhobosController new]; GMPhobosController *controller = [GMPhobosController new];
controller.isPush = @"1";
controller.pageName = @"pageNameTest"; controller.pageName = @"pageNameTest";
controller.businessId = @"businessIdTest"; controller.businessId = @"businessIdTest";
controller.referrerId = @"rreferrerIdTest"; controller.referrerId = @"rreferrerIdTest";
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "GMPhobos" s.name = "GMPhobos"
s.version = "2.0.0" s.version = "2.0.1"
s.summary = "GM statistic data sdk" s.summary = "GM statistic data sdk"
s.description = <<-DESC s.description = <<-DESC
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#import "PhobosSendManager.h" #import "PhobosSendManager.h"
static NewPhobos *_sharedClient; static NewPhobos *_sharedClient;
static NSString *sdkVersion = @"2.0.0";
@interface NewPhobos () @interface NewPhobos ()
@property (strong, nonatomic) UIViewController *visibleController; @property (strong, nonatomic) UIViewController *visibleController;
...@@ -268,23 +267,19 @@ static NSString *sdkVersion = @"2.0.0"; ...@@ -268,23 +267,19 @@ static NSString *sdkVersion = @"2.0.0";
} }
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
@try { @try {
[dict setObject:[PhobosUtil currentTime] forKey:@"out"]; [dict setObject:PhobosSafeString([PhobosUtil currentTime]) forKey:@"out"];
[dict setObject:page.inTime?:@"" forKey:@"in"]; [dict setObject:PhobosSafeString(page.inTime) forKey:@"in"];
[dict setObject:page.pageName forKey:@"page_name"]; [dict setObject:PhobosSafeString(page.pageName) forKey:@"page_name"];
[dict setObject:page.businessId?:@"" forKey:@"business_id"]; [dict setObject:PhobosSafeString(page.businessId) forKey:@"business_id"];
[dict setObject:page.referer?:@"" forKey:@"referrer"]; [dict setObject:PhobosSafeString(page.referer) forKey:@"referrer"];
if ([page.referrerLink isKindOfClass:[NSArray class]] && page.referrerLink.count) { [dict setObject:PhobosSafeString([PhobosUtil convertToJsonString:page.referrerLink]) forKey:@"referrer_link"];
[dict setObject:page.referrerLink forKey:@"referrer_link"];
} else {
[dict setObject:@[] forKey:@"referrer_link"];
}
[dict setObject:@(0) forKey:@"fake"]; [dict setObject:@(0) forKey:@"fake"];
[dict setObject:page.referrerId ? : @"" forKey:@"referrer_id"]; [dict setObject:PhobosSafeString(page.referrerId) forKey:@"referrer_id"];
[dict setObject:page.extraParam ? : @"" forKey:@"extra_param"]; [dict setObject:PhobosSafeString(page.extraParam) forKey:@"extra_param"];
[dict setObject:page.referrerTabName ? : @"" forKey:@"referrer_tab_name"]; [dict setObject:PhobosSafeString(page.referrerTabName) forKey:@"referrer_tab_name"];
[dict setObject:page.isPush.intValue ? @(page.isPush.intValue) : @(0) forKey:@"is_push"]; [dict setObject:page.isPush.intValue ? @(page.isPush.intValue) : @(0) forKey:@"is_push"];
[dict setObject:page.inTimeMillis?:@"" forKey:@"in_time_millis"]; [dict setObject:PhobosSafeString(page.inTimeMillis) forKey:@"in_time_millis"];
[dict setObject:[PhobosUtil currentMMTime] forKey:@"out_time_millis"]; [dict setObject:PhobosSafeString([PhobosUtil currentMMTime]) forKey:@"out_time_millis"];
if (page.inTime.length > 0) { if (page.inTime.length > 0) {
// 页面显示时间为空时不记录页面pv事件 // 页面显示时间为空时不记录页面pv事件
...@@ -319,44 +314,44 @@ static NSString *sdkVersion = @"2.0.0"; ...@@ -319,44 +314,44 @@ static NSString *sdkVersion = @"2.0.0";
NSString *currentTime = [PhobosUtil currentTime]; NSString *currentTime = [PhobosUtil currentTime];
NSMutableDictionary *deviceParams = [NSMutableDictionary new]; NSMutableDictionary *deviceParams = [NSMutableDictionary new];
[deviceParams setValue:[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString] forKey:@"idfa"]; [deviceParams setValue:PhobosSafeString([[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]) forKey:@"idfa"];
[deviceParams setValue:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forKey:@"idfv"]; [deviceParams setValue:PhobosSafeString([[[UIDevice currentDevice] identifierForVendor] UUIDString]) forKey:@"idfv"];
[deviceParams setValue:[PhobosUtil deviceId] forKey:@"device_id"]; [deviceParams setValue:PhobosSafeString([PhobosUtil deviceId]) forKey:@"device_id"];
[deviceParams setValue:@"ios" forKey:@"device_type"]; [deviceParams setValue:@"ios" forKey:@"device_type"];
[deviceParams setValue:@"Apple" forKey:@"manufacturer"]; [deviceParams setValue:@"Apple" forKey:@"manufacturer"];
[deviceParams setValue:@(self.gps.coordinate.latitude) forKey:@"lat"]; [deviceParams setValue:@(self.gps.coordinate.latitude) forKey:@"lat"];
[deviceParams setValue:@(self.gps.coordinate.longitude) forKey:@"lng"]; [deviceParams setValue:@(self.gps.coordinate.longitude) forKey:@"lng"];
[deviceParams setValue:_netStatus forKey:@"is_WiFi"]; [deviceParams setValue:PhobosSafeString(_netStatus) forKey:@"is_WiFi"];
[deviceParams setValue:[PhobosUtil getIPAddress:YES] forKey:@"ip"]; [deviceParams setValue:[PhobosUtil getIPAddress:YES] forKey:@"ip"];
[deviceParams setValue:_networkStatus forKey:@"net_type"]; [deviceParams setValue:PhobosSafeString(_networkStatus) forKey:@"net_type"];
[deviceParams setValue:[PhobosUtil platform] forKey:@"model"]; [deviceParams setValue:PhobosSafeString([PhobosUtil platform]) forKey:@"model"];
[deviceParams setValue:@(_isGray) forKey:@"isGray"]; [deviceParams setValue:@(_isGray) forKey:@"isGray"];
[deviceParams setValue:[UIDevice currentDevice].systemVersion forKey:@"sys_version"]; [deviceParams setValue:PhobosSafeString([UIDevice currentDevice].systemVersion) forKey:@"sys_version"];
NSMutableDictionary *appParams = [NSMutableDictionary new]; NSMutableDictionary *appParams = [NSMutableDictionary new];
[appParams setValue:_greyType forKey:@"grey_type"]; [appParams setValue:PhobosSafeString(_greyType) forKey:@"grey_type"];
[appParams setValue:_appName forKey:@"name"]; [appParams setValue:PhobosSafeString(_appName) forKey:@"name"];
[appParams setValue:_appVersion forKey:@"version"]; [appParams setValue:PhobosSafeString(_appVersion) forKey:@"version"];
[appParams setValue:_channelId forKey:@"channel"]; [appParams setValue:PhobosSafeString(_channelId) forKey:@"channel"];
[appParams setValue:_userType forKey:@"user_type"]; [appParams setValue:PhobosSafeString(_userType) forKey:@"user_type"];
[appParams setValue:_currentCityId forKey:@"current_city_id"]; [appParams setValue:PhobosSafeString(_currentCityId) forKey:@"current_city_id"];
[appParams setValue:@(_serialId++) forKey:@"serial_id"]; [appParams setValue:@(_serialId++) forKey:@"serial_id"];
if (_signingType == PhobosSigningTypeDebug || _signingType == PhobosSigningTypeRelease) { if (_signingType == PhobosSigningTypeDebug || _signingType == PhobosSigningTypeRelease) {
[dict setObject:@(0) forKey:@"is_release"]; [dict setValue:@(0) forKey:@"is_release"];
} }
NSString *nano_time = [NSString stringWithFormat:@"%lld",[[NSProcessInfo processInfo] systemUptime]]; NSString *nano_time = [NSString stringWithFormat:@"%lld",[[NSProcessInfo processInfo] systemUptime]];
[dict setObject:eventName forKey:@"type"]; [dict setValue:eventName forKey:@"type"];
[dict setObject:appParams forKey:@"app"]; [dict setValue:appParams forKey:@"app"];
[dict setObject:sdkVersion forKey:@"version"]; [dict setValue:sdkVersion forKey:@"version"];
[dict setObject:deviceParams forKey:@"device"]; [dict setValue:deviceParams forKey:@"device"];
[dict setObject:_userId forKey:@"user_id"]; [dict setValue:PhobosSafeString(_userId) forKey:@"user_id"];
[dict setObject:currentTime forKey:@"create_at"];// 1584513842 当前时间(秒) [dict setValue:PhobosSafeString(currentTime) forKey:@"create_at"];// 1584513842 当前时间(秒)
[dict setObject:nano_time?:@"" forKey:@"nano_time"];// 1657008897 系统启动后时长(秒) [dict setValue:PhobosSafeString(nano_time) forKey:@"nano_time"];// 1657008897 系统启动后时长(秒)
[dict setObject:@(mach_absolute_time()) forKey:@"absolute_time"];// 148237263697318 系统启动后的 CPU 嘀嗒数(纳秒) [dict setValue:@(mach_absolute_time()) forKey:@"absolute_time"];// 148237263697318 系统启动后的 CPU 嘀嗒数(纳秒)
[dict setObject:[PhobosUtil currentMMTime] forKey:@"create_at_millis"];// 1584513842753 当前时间戳(毫秒) [dict setValue:PhobosSafeString([PhobosUtil currentMMTime]) forKey:@"create_at_millis"];// 1584513842753 当前时间戳(毫秒)
[dict setObject:attributes forKey:@"params"]; [dict setValue:attributes forKey:@"params"];
[dict setObject:_sessionId forKey:@"app_session_id"]; [dict setValue:PhobosSafeString(_sessionId) forKey:@"app_session_id"];
} }
@catch (NSException *exception) { @catch (NSException *exception) {
phobosLog(exception); phobosLog(exception);
...@@ -430,8 +425,8 @@ static NSString *sdkVersion = @"2.0.0"; ...@@ -430,8 +425,8 @@ static NSString *sdkVersion = @"2.0.0";
[PhobosDataManager updateDataEntities:entities sendStatus:PhobosDataSendStatusSending]; [PhobosDataManager updateDataEntities:entities sendStatus:PhobosDataSendStatusSending];
[PhobosSendManager sendDataWithEntities:entities completion:^(NSArray<PhobosSendDataEntity *> * _Nonnull finishEntities, NSInteger code) { [PhobosSendManager sendDataWithEntities:entities completion:^(NSArray<PhobosSendDataEntity *> * _Nonnull finishEntities, NSInteger code) {
if (code == 200) { if (code == 200) {
[PhobosDataManager deleteDataEntities:finishEntities];
[PhobosDataManager updateDataEntities:finishEntities sendStatus:PhobosDataSendStatusFinish]; [PhobosDataManager updateDataEntities:finishEntities sendStatus:PhobosDataSendStatusFinish];
[PhobosDataManager deleteDataEntities:finishEntities];
} else { } else {
[PhobosDataManager updateDataEntities:finishEntities sendStatus:PhobosDataSendStatusError]; [PhobosDataManager updateDataEntities:finishEntities sendStatus:PhobosDataSendStatusError];
} }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#import <mach/mach_time.h> #import <mach/mach_time.h>
static OldPhobos *sharedClient = nil; static OldPhobos *sharedClient = nil;
static NSString *sdkVersion = @"2.0.0";
@interface OldPhobos () @interface OldPhobos ()
@property (strong, nonatomic) UIViewController *visibleController; @property (strong, nonatomic) UIViewController *visibleController;
...@@ -349,23 +348,19 @@ static NSString *sdkVersion = @"2.0.0"; ...@@ -349,23 +348,19 @@ static NSString *sdkVersion = @"2.0.0";
} }
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
@try { @try {
[dict setObject:[PhobosUtil currentTime] forKey:@"out"]; [dict setObject:PhobosSafeString([PhobosUtil currentTime]) forKey:@"out"];
[dict setObject:page.inTime?:@"" forKey:@"in"]; [dict setObject:PhobosSafeString(page.inTime) forKey:@"in"];
[dict setObject:page.pageName forKey:@"page_name"]; [dict setObject:PhobosSafeString(page.pageName) forKey:@"page_name"];
[dict setObject:page.businessId?:@"" forKey:@"business_id"]; [dict setObject:PhobosSafeString(page.businessId) forKey:@"business_id"];
[dict setObject:page.referer?:@"" forKey:@"referrer"]; [dict setObject:PhobosSafeString(page.referer) forKey:@"referrer"];
if ([page.referrerLink isKindOfClass:[NSArray class]] && page.referrerLink.count) { [dict setObject:PhobosSafeString([PhobosUtil convertToJsonString:page.referrerLink]) forKey:@"referrer_link"];
[dict setObject:page.referrerLink forKey:@"referrer_link"];
} else {
[dict setObject:@[] forKey:@"referrer_link"];
}
[dict setObject:@(0) forKey:@"fake"]; [dict setObject:@(0) forKey:@"fake"];
[dict setObject:page.referrerId ? : @"" forKey:@"referrer_id"]; [dict setObject:PhobosSafeString(page.referrerId) forKey:@"referrer_id"];
[dict setObject:page.extraParam ? : @"" forKey:@"extra_param"]; [dict setObject:PhobosSafeString(page.extraParam) forKey:@"extra_param"];
[dict setObject:page.referrerTabName ? : @"" forKey:@"referrer_tab_name"]; [dict setObject:PhobosSafeString(page.referrerTabName) forKey:@"referrer_tab_name"];
[dict setObject:page.isPush.intValue ? @(page.isPush.intValue) : @(0) forKey:@"is_push"]; [dict setObject:page.isPush.intValue ? @(page.isPush.intValue) : @(0) forKey:@"is_push"];
[dict setObject:page.inTimeMillis?:@"" forKey:@"in_time_millis"]; [dict setObject:PhobosSafeString(page.inTimeMillis) forKey:@"in_time_millis"];
[dict setObject:[PhobosUtil currentMMTime] forKey:@"out_time_millis"]; [dict setObject:PhobosSafeString([PhobosUtil currentMMTime]) forKey:@"out_time_millis"];
if (page.inTime.length > 0) { if (page.inTime.length > 0) {
// 页面显示时间为空时不记录页面pv事件 // 页面显示时间为空时不记录页面pv事件
...@@ -419,43 +414,44 @@ static NSString *sdkVersion = @"2.0.0"; ...@@ -419,43 +414,44 @@ static NSString *sdkVersion = @"2.0.0";
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
@try { @try {
NSString *currentTime = [PhobosUtil currentTime]; NSString *currentTime = [PhobosUtil currentTime];
NSMutableDictionary *deviceParams = [NSMutableDictionary dictionaryWithObjectsAndKeys: NSMutableDictionary *deviceParams = [NSMutableDictionary new];
[[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString],@"idfa", [deviceParams setValue:PhobosSafeString([[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]) forKey:@"idfa"];
[[[UIDevice currentDevice] identifierForVendor] UUIDString],@"idfv", [deviceParams setValue:PhobosSafeString([[[UIDevice currentDevice] identifierForVendor] UUIDString]) forKey:@"idfv"];
[PhobosUtil deviceId],@"device_id", [deviceParams setValue:PhobosSafeString([PhobosUtil deviceId]) forKey:@"device_id"];
@"ios",@"device_type", [deviceParams setValue:@"ios" forKey:@"device_type"];
@"Apple",@"manufacturer", [deviceParams setValue:@"Apple" forKey:@"manufacturer"];
@(self.gps.coordinate.latitude),@"lat", [deviceParams setValue:@(self.gps.coordinate.latitude) forKey:@"lat"];
@(self.gps.coordinate.longitude),@"lng", [deviceParams setValue:@(self.gps.coordinate.longitude) forKey:@"lng"];
_netStatus,@"is_WiFi", [deviceParams setValue:PhobosSafeString(_netStatus) forKey:@"is_WiFi"];
[PhobosUtil getIPAddress:YES],@"ip",nil]; [deviceParams setValue:[PhobosUtil getIPAddress:YES] forKey:@"ip"];
[deviceParams setValue:_networkStatus forKey:@"net_type"]; [deviceParams setValue:PhobosSafeString(_networkStatus) forKey:@"net_type"];
[deviceParams setValue:[PhobosUtil platform] forKey:@"model"]; [deviceParams setValue:PhobosSafeString([PhobosUtil platform]) forKey:@"model"];
[deviceParams setValue:[UIDevice currentDevice].systemVersion forKey:@"sys_version"]; [deviceParams setValue:PhobosSafeString([UIDevice currentDevice].systemVersion) forKey:@"sys_version"];
NSMutableDictionary *appParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_greyType, @"grey_type", NSMutableDictionary *appParams = [NSMutableDictionary new];
self.appName, @"name", [appParams setValue:PhobosSafeString(_greyType) forKey:@"grey_type"];
self.appVersion, @"version", [appParams setValue:PhobosSafeString(_appName) forKey:@"name"];
self.channelId,@"channel", [appParams setValue:PhobosSafeString(_appVersion) forKey:@"version"];
_userType,@"user_type", [appParams setValue:PhobosSafeString(_channelId) forKey:@"channel"];
self.currentCityId,@"current_city_id", [appParams setValue:PhobosSafeString(_userType) forKey:@"user_type"];
@(_serialId++), @"serial_id",nil]; [appParams setValue:PhobosSafeString(_currentCityId) forKey:@"current_city_id"];
[appParams setValue:@(_serialId++) forKey:@"serial_id"];
if (_signingType == PhobosSigningTypeDebug || _signingType == PhobosSigningTypeRelease) { if (_signingType == PhobosSigningTypeDebug || _signingType == PhobosSigningTypeRelease) {
[dict setObject:@(0) forKey:@"is_release"]; [dict setValue:@(0) forKey:@"is_release"];
} }
NSString *nano_time = [NSString stringWithFormat:@"%lld",[[NSProcessInfo processInfo] systemUptime]]; NSString *nano_time = [NSString stringWithFormat:@"%lld",[[NSProcessInfo processInfo] systemUptime]];
[dict setObject:eventId forKey:@"type"]; [dict setValue:eventId forKey:@"type"];
[dict setObject:appParams forKey:@"app"]; [dict setValue:appParams forKey:@"app"];
[dict setObject:sdkVersion forKey:@"version"]; [dict setValue:sdkVersion forKey:@"version"];
[dict setObject:deviceParams forKey:@"device"]; [dict setValue:deviceParams forKey:@"device"];
[dict setObject:_userId forKey:@"user_id"]; [dict setValue:PhobosSafeString(_userId) forKey:@"user_id"];
[dict setObject:currentTime forKey:@"create_at"];// 1584513842 当前时间(秒) [dict setValue:PhobosSafeString(currentTime) forKey:@"create_at"];// 1584513842 当前时间(秒)
[dict setObject:nano_time?:@"" forKey:@"nano_time"];// 1657008897 系统启动后时长(秒) [dict setValue:PhobosSafeString(nano_time) forKey:@"nano_time"];// 1657008897 系统启动后时长(秒)
[dict setObject:@(mach_absolute_time()) forKey:@"absolute_time"];// 148237263697318 系统启动后的 CPU 嘀嗒数(纳秒) [dict setValue:@(mach_absolute_time()) forKey:@"absolute_time"];// 148237263697318 系统启动后的 CPU 嘀嗒数(纳秒)
[dict setObject:[PhobosUtil currentMMTime] forKey:@"create_at_millis"];// 1584513842753 当前时间戳(毫秒) [dict setValue:PhobosSafeString([PhobosUtil currentMMTime]) forKey:@"create_at_millis"];// 1584513842753 当前时间戳(毫秒)
[dict setObject:attributes forKey:@"params"]; [dict setValue:attributes forKey:@"params"];
[dict setObject:_sessionId forKey:@"app_session_id"]; [dict setValue:PhobosSafeString(_sessionId) forKey:@"app_session_id"];
} }
@catch (NSException *exception) { @catch (NSException *exception) {
phobosLog(exception); phobosLog(exception);
......
...@@ -47,6 +47,7 @@ static BOOL isGray = NO; ...@@ -47,6 +47,7 @@ static BOOL isGray = NO;
- (instancetype)initWithAppName:(NSString *)appName channelId:(NSString *)channelId{ - (instancetype)initWithAppName:(NSString *)appName channelId:(NSString *)channelId{
if (self = [super init]) { if (self = [super init]) {
isGray = [[[NSUserDefaults standardUserDefaults] objectForKey:PhobosGray] boolValue]; isGray = [[[NSUserDefaults standardUserDefaults] objectForKey:PhobosGray] boolValue];
// isGray在config接口获取,会保存在NSUserDefaults的PhobosGray中,当次不使用,在下一次冷启动通过该灰度,初始化埋点库
if (isGray) { if (isGray) {
_rePhobos = [NewPhobos clientWithAppName:appName channelId:channelId]; _rePhobos = [NewPhobos clientWithAppName:appName channelId:channelId];
sharedClient = _rePhobos; sharedClient = _rePhobos;
...@@ -139,79 +140,89 @@ static BOOL isGray = NO; ...@@ -139,79 +140,89 @@ static BOOL isGray = NO;
} }
- (void)setCaptureNullExpection:(void (^)(NSString * _Nonnull, NSDictionary * _Nonnull))captureNullExpection { - (void)setCaptureNullExpection:(void (^)(NSString * _Nonnull, NSDictionary * _Nonnull))captureNullExpection {
_captureNullExpection = captureNullExpection;
_rePhobos.captureNullExpection = captureNullExpection; _rePhobos.captureNullExpection = captureNullExpection;
_oldPhobos.captureNullExpection = captureNullExpection; _oldPhobos.captureNullExpection = captureNullExpection;
} }
- (void)setNetStatus:(NSString *)netStatus { - (void)setNetStatus:(NSString *)netStatus {
_netStatus = netStatus;
_rePhobos.netStatus = netStatus; _rePhobos.netStatus = netStatus;
_oldPhobos.netStatus = netStatus; _oldPhobos.netStatus = netStatus;
} }
- (void)setNetworkStatus:(NSString *)networkStatus { - (void)setNetworkStatus:(NSString *)networkStatus {
_networkStatus = networkStatus;
_rePhobos.networkStatus = networkStatus; _rePhobos.networkStatus = networkStatus;
_oldPhobos.networkStatus = networkStatus; _oldPhobos.networkStatus = networkStatus;
} }
- (void)setLogEnabled:(BOOL)logEnabled { - (void)setLogEnabled:(BOOL)logEnabled {
_logEnabled = logEnabled;
_rePhobos.logEnabled = logEnabled; _rePhobos.logEnabled = logEnabled;
_oldPhobos.logEnabled = logEnabled; _oldPhobos.logEnabled = logEnabled;
} }
- (void)setUserId:(NSString *)userId { - (void)setUserId:(NSString *)userId {
_userId = userId;
_rePhobos.userId = userId; _rePhobos.userId = userId;
_oldPhobos.userId = userId; _oldPhobos.userId = userId;
} }
- (void)setCurrentCityId:(NSString *)currentCityId { - (void)setCurrentCityId:(NSString *)currentCityId {
_currentCityId = currentCityId;
_rePhobos.currentCityId = currentCityId; _rePhobos.currentCityId = currentCityId;
_oldPhobos.currentCityId = currentCityId; _oldPhobos.currentCityId = currentCityId;
} }
- (void)setGps:(CLLocation *)gps { - (void)setGps:(CLLocation *)gps {
_gps = gps;
_rePhobos.gps = gps; _rePhobos.gps = gps;
_oldPhobos.gps = gps; _oldPhobos.gps = gps;
} }
- (void)setUserType:(NSMutableDictionary *)userType { - (void)setUserType:(NSMutableDictionary *)userType {
_userType = userType;
_rePhobos.userType = userType; _rePhobos.userType = userType;
_oldPhobos.userType = userType; _oldPhobos.userType = userType;
} }
- (void)setApiHost:(NSString *)apiHost { - (void)setApiHost:(NSString *)apiHost {
_apiHost = apiHost;
_rePhobos.apiHost = apiHost; _rePhobos.apiHost = apiHost;
_oldPhobos.apiHost = apiHost; _oldPhobos.apiHost = apiHost;
} }
- (void)setServerAPI:(NSString *)serverAPI { - (void)setServerAPI:(NSString *)serverAPI {
_serverAPI = serverAPI;
_rePhobos.serverAPI = serverAPI; _rePhobos.serverAPI = serverAPI;
_oldPhobos.serverAPI = serverAPI; _oldPhobos.serverAPI = serverAPI;
} }
-(void)setCookie:(NSString *)cookie { -(void)setCookie:(NSString *)cookie {
_cookie = cookie;
_rePhobos.cookie = cookie; _rePhobos.cookie = cookie;
_oldPhobos.cookie = cookie; _oldPhobos.cookie = cookie;
} }
- (void)setGreyType:(NSString *)greyType { - (void)setGreyType:(NSString *)greyType {
_greyType = greyType;
_rePhobos.greyType = greyType; _rePhobos.greyType = greyType;
_oldPhobos.greyType = greyType; _oldPhobos.greyType = greyType;
} }
- (void)setSigningType:(PhobosSigningType)signingType { - (void)setSigningType:(PhobosSigningType)signingType {
_signingType = signingType;
_rePhobos.signingType = signingType; _rePhobos.signingType = signingType;
_oldPhobos.signingType = signingType; _oldPhobos.signingType = signingType;
} }
- (void)setGetTopController:(UIViewController * _Nonnull (^)(void))getTopController { - (void)setGetTopController:(UIViewController * _Nonnull (^)(void))getTopController {
_getTopController = getTopController;
_rePhobos.getTopController = getTopController; _rePhobos.getTopController = getTopController;
_oldPhobos.getTopController = getTopController; _oldPhobos.getTopController = getTopController;
} }
- (NSString *)serverAPI {
return isGray ? _rePhobos.serverAPI : _oldPhobos.serverAPI;
}
@end @end
......
...@@ -16,6 +16,7 @@ typedef NS_ENUM (NSInteger, PhobosSigningType) { ...@@ -16,6 +16,7 @@ typedef NS_ENUM (NSInteger, PhobosSigningType) {
PhobosSigningTypeDebug PhobosSigningTypeDebug
}; };
static NSString *sdkVersion = @"2.0.1";
#ifdef DEBUG #ifdef DEBUG
#define phobosLog(...) NSLog(@"[Phobos] %@",__VA_ARGS__) #define phobosLog(...) NSLog(@"[Phobos] %@",__VA_ARGS__)
...@@ -33,4 +34,6 @@ typedef NS_ENUM (NSInteger, PhobosSigningType) { ...@@ -33,4 +34,6 @@ typedef NS_ENUM (NSInteger, PhobosSigningType) {
#define PhobosShardCount 50 //收集数据分段发送的个数 #define PhobosShardCount 50 //收集数据分段发送的个数
#define PhobosMaxSendCount 100 // 最大发送数量 #define PhobosMaxSendCount 100 // 最大发送数量
#define PhobosSafeString(string) (string ?: @"")
#endif /* PhobosConfig_h */ #endif /* PhobosConfig_h */
...@@ -22,14 +22,45 @@ typedef NS_ENUM(NSInteger, PhobosDataSendStatus) { ...@@ -22,14 +22,45 @@ typedef NS_ENUM(NSInteger, PhobosDataSendStatus) {
/** 获取待发送数据,包含待发送数据和发送失败数据 */ /** 获取待发送数据,包含待发送数据和发送失败数据 */
+ (NSArray<PhobosSendDataEntity *> *)fetchToBeSendDataEntities; + (NSArray<PhobosSendDataEntity *> *)fetchToBeSendDataEntities;
/**
* 通过 searchFilter 获取数据
*/
+ (NSArray<PhobosSendDataEntity *> *)fetchDataEntitiesWithPredicate:(NSPredicate *)searchFilter; + (NSArray<PhobosSendDataEntity *> *)fetchDataEntitiesWithPredicate:(NSPredicate *)searchFilter;
/**
* 获取待发送和发送失败的数据数量
*/
+ (NSUInteger)fetchCountOfToBeSendEntities; + (NSUInteger)fetchCountOfToBeSendEntities;
/**
* 通过 searchFilter 获取数据数量
*/
+ (NSUInteger)fetchCountOfEntitiesWithPredicate:(NSPredicate *)searchFilter; + (NSUInteger)fetchCountOfEntitiesWithPredicate:(NSPredicate *)searchFilter;
/**
* 插入埋点数据
* data 埋点参数
* sendAPI 数据接收的服务器API
* completion 插入数据库成功后的回调方法,在保存完成后调用的完成块。如果发生错误,块将以“BOOL”和“NSError”实例的形式传递成功状态。总是在主队列上调用。
* 该方法调用完成,fetch方法获取相应的数据就可获取到,不需要等completion回调。
*/
+ (void)insertData:(NSDictionary *)data sendAPI:(NSString *)sendAPI; + (void)insertData:(NSDictionary *)data sendAPI:(NSString *)sendAPI;
+ (void)insertData:(NSDictionary *)data sendAPI:(NSString *)sendAPI completion:(MRSaveCompletionHandler)completion;
/**
* 修改埋点数据
* entities 需要修改的实体
* sendStatus 需要修改为的状态,
* completion 插入数据库成功后的回调方法,在保存完成后调用的完成块。如果发生错误,块将以“BOOL”和“NSError”实例的形式传递成功状态。总是在主队列上调用。
* 该方法调用完成,fetch方法获取相应的数据就可获取到,不需要等completion回调。
*/
+ (void)updateDataEntities:(NSArray<PhobosSendDataEntity *> *)entities sendStatus:(PhobosDataSendStatus)sendStatus; + (void)updateDataEntities:(NSArray<PhobosSendDataEntity *> *)entities sendStatus:(PhobosDataSendStatus)sendStatus;
+ (void)updateDataEntities:(NSArray<PhobosSendDataEntity *> *)entities sendStatus:(PhobosDataSendStatus)sendStatus completion:(MRSaveCompletionHandler)completion;
/**
* 删除数据
*/
+ (void)deleteDataEntities:(NSArray<PhobosSendDataEntity *> *)entities; + (void)deleteDataEntities:(NSArray<PhobosSendDataEntity *> *)entities;
+ (void)deleteAllEntities; + (void)deleteAllEntities;
......
...@@ -19,8 +19,10 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -19,8 +19,10 @@ static NSManagedObjectContext *Phobos_defaultContext;
+ (void)initialize { + (void)initialize {
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
// 创建 NSManagedObjectContext,供埋点库访问CoreData库使用
Phobos_defaultContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; Phobos_defaultContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSBundle *bundle = [NSBundle bundleForClass:[self class]];
// 获取埋点数据的实体
NSURL *modelURL = [bundle URLForResource:@"GMPhobosData" withExtension:@"momd"]; NSURL *modelURL = [bundle URLForResource:@"GMPhobosData" withExtension:@"momd"];
NSManagedObjectModel *model = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; NSManagedObjectModel *model = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
...@@ -33,11 +35,18 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -33,11 +35,18 @@ static NSManagedObjectContext *Phobos_defaultContext;
[coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[NSURL fileURLWithPath:dataPath] options:nil error:nil]; [coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[NSURL fileURLWithPath:dataPath] options:nil error:nil];
// 设置storeCoordinator
Phobos_defaultContext.persistentStoreCoordinator = coordinator; Phobos_defaultContext.persistentStoreCoordinator = coordinator;
/** 将上次没有获取到发送结果的数据的状态修改为发送失败,待下次重新发送 */
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status = %d", PhobosDataSendStatusSending]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status = %d", PhobosDataSendStatusSending];
NSArray<PhobosSendDataEntity *> *entities = [self fetchDataEntitiesWithPredicate:predicate]; NSArray<PhobosSendDataEntity *> *entities = [self fetchDataEntitiesWithPredicate:predicate];
[self updateDataEntities:entities sendStatus:PhobosDataSendStatusError]; [self updateDataEntities:entities sendStatus:PhobosDataSendStatusError];
/** 将发送成功的数据删除 */
NSPredicate *finishPredicate = [NSPredicate predicateWithFormat:@"status = %d", PhobosDataSendStatusFinish];
NSArray<PhobosSendDataEntity *> *finishEntities = [self fetchDataEntitiesWithPredicate:finishPredicate];
[self deleteDataEntities:finishEntities];
}); });
} }
...@@ -60,6 +69,10 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -60,6 +69,10 @@ static NSManagedObjectContext *Phobos_defaultContext;
} }
+ (void)insertData:(NSDictionary *)data sendAPI:(NSString *)sendAPI { + (void)insertData:(NSDictionary *)data sendAPI:(NSString *)sendAPI {
[self insertData:data sendAPI:sendAPI completion:nil];
}
+ (void)insertData:(NSDictionary *)data sendAPI:(NSString *)sendAPI completion:(MRSaveCompletionHandler)completion {
if (!sendAPI || [sendAPI isEqualToString:@""] || !data) { if (!sendAPI || [sendAPI isEqualToString:@""] || !data) {
return; return;
} }
...@@ -68,15 +81,19 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -68,15 +81,19 @@ static NSManagedObjectContext *Phobos_defaultContext;
entity.api = sendAPI; entity.api = sendAPI;
entity.status = PhobosDataSendStatusToBeSend; entity.status = PhobosDataSendStatusToBeSend;
entity.id = mach_absolute_time(); entity.id = mach_absolute_time();
[Phobos_defaultContext MR_saveOnlySelfWithCompletion:nil]; [self saveWithCompletion:completion];
} }
+ (void)updateDataEntities:(NSArray<PhobosSendDataEntity *> *)entities sendStatus:(PhobosDataSendStatus)sendStatus { + (void)updateDataEntities:(NSArray<PhobosSendDataEntity *> *)entities sendStatus:(PhobosDataSendStatus)sendStatus {
[self updateDataEntities:entities sendStatus:sendStatus completion:nil];
}
+ (void)updateDataEntities:(NSArray<PhobosSendDataEntity *> *)entities sendStatus:(PhobosDataSendStatus)sendStatus completion:(MRSaveCompletionHandler)completion {
if (entities.count > 0) { if (entities.count > 0) {
[entities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) { [entities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) {
obj.status = sendStatus; obj.status = sendStatus;
}]; }];
[Phobos_defaultContext MR_saveOnlySelfWithCompletion:nil]; [self saveWithCompletion:completion];
} }
} }
...@@ -85,13 +102,20 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -85,13 +102,20 @@ static NSManagedObjectContext *Phobos_defaultContext;
[entities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) { [entities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj MR_deleteEntityInContext:Phobos_defaultContext]; [obj MR_deleteEntityInContext:Phobos_defaultContext];
}]; }];
[Phobos_defaultContext MR_saveOnlySelfWithCompletion:nil]; [self saveWithCompletion:nil];
} }
} }
+ (void)deleteAllEntities { + (void)deleteAllEntities {
[PhobosSendDataEntity MR_truncateAllInContext:Phobos_defaultContext]; [PhobosSendDataEntity MR_truncateAllInContext:Phobos_defaultContext];
[Phobos_defaultContext MR_saveOnlySelfWithCompletion:nil]; [self saveWithCompletion:nil];
}
/**
* 在保存完成后调用的完成块。如果发生错误,块将以“BOOL”和“NSError”实例的形式传递成功状态。总是在主队列上调用。
*/
+ (void)saveWithCompletion:(MRSaveCompletionHandler)completion {
[Phobos_defaultContext MR_saveOnlySelfWithCompletion:completion];
} }
@end @end
...@@ -83,7 +83,7 @@ typedef void(^PhobosUpdatePVBlock)(void); ...@@ -83,7 +83,7 @@ typedef void(^PhobosUpdatePVBlock)(void);
/** /**
获取上一个页面链路的page_name link by 7.20.0 如果有此页面有page_name则添加 , 没有添加"" 获取上一个页面链路的page_name link by 7.20.0 如果有此页面有page_name则添加 , 没有添加""
*/ */
@property (nonatomic, copy) NSArray *referrerLink; @property (nonatomic, strong) NSArray *referrerLink;
/// 业务层更新PVStart信息 /// 业务层更新PVStart信息
@property (nonatomic, copy) PhobosUpdatePVBlock updatePVStartBlock; @property (nonatomic, copy) PhobosUpdatePVBlock updatePVStartBlock;
......
...@@ -12,9 +12,11 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -12,9 +12,11 @@ NS_ASSUME_NONNULL_BEGIN
@interface PhobosSendManager : NSObject @interface PhobosSendManager : NSObject
/**
* 发送数据
*/
+ (void)sendDataWithEntities:(NSArray<PhobosSendDataEntity *> *)needSendData completion:(nullable void(^)(NSArray<PhobosSendDataEntity *> *finishEntities, NSInteger code))completion; + (void)sendDataWithEntities:(NSArray<PhobosSendDataEntity *> *)needSendData completion:(nullable void(^)(NSArray<PhobosSendDataEntity *> *finishEntities, NSInteger code))completion;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
+ (void)initialize { + (void)initialize {
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
// 处理非灰情况下未发送完成数据
[self disposeOldData]; [self disposeOldData];
}); });
} }
...@@ -35,6 +36,7 @@ ...@@ -35,6 +36,7 @@
[total addObjectsFromArray:normalDataArray]; [total addObjectsFromArray:normalDataArray];
[total addObjectsFromArray:immiDataArray]; [total addObjectsFromArray:immiDataArray];
if (total.count > 0) { if (total.count > 0) {
/** 获取非灰度下所有普通埋点,进行发送 */
[self sendDataArray:total currentAPI:Phobos.sharedClient.serverAPI success:^(NSInteger code) { [self sendDataArray:total currentAPI:Phobos.sharedClient.serverAPI success:^(NSInteger code) {
if (code == 200) { if (code == 200) {
[GMCache removeObjectAtDocumentPathWithkey:PhobosCacheKey]; [GMCache removeObjectAtDocumentPathWithkey:PhobosCacheKey];
...@@ -45,6 +47,7 @@ ...@@ -45,6 +47,7 @@
NSString *exposureAPI = GMExactExposureApi; NSString *exposureAPI = GMExactExposureApi;
NSArray *exposureArray = [GMCache fetchObjectAtDocumentPathWithkey:[PhobosUtil MD5String:exposureAPI]]; NSArray *exposureArray = [GMCache fetchObjectAtDocumentPathWithkey:[PhobosUtil MD5String:exposureAPI]];
if (exposureArray.count > 0) { if (exposureArray.count > 0) {
/** 获取非灰度下发送失败的埋点,进行发送 */
[self sendDataArray:exposureArray currentAPI:exposureAPI success:^(NSInteger code) { [self sendDataArray:exposureArray currentAPI:exposureAPI success:^(NSInteger code) {
if (code = 200) { if (code = 200) {
[GMCache removeObjectAtDocumentPathWithkey:[PhobosUtil MD5String:exposureAPI]]; [GMCache removeObjectAtDocumentPathWithkey:[PhobosUtil MD5String:exposureAPI]];
...@@ -57,9 +60,11 @@ ...@@ -57,9 +60,11 @@
if (sendDataEntities.count == 0) { if (sendDataEntities.count == 0) {
return; return;
} else if (sendDataEntities.count > PhobosMaxSendCount) { } else if (sendDataEntities.count > PhobosMaxSendCount) {
/** 如果数据超过 PhobosMaxSendCount 数据规模,进行拆分,分批发送,默认100条 */
NSMutableArray *temp = [NSMutableArray arrayWithCapacity:PhobosMaxSendCount]; NSMutableArray *temp = [NSMutableArray arrayWithCapacity:PhobosMaxSendCount];
[sendDataEntities enumerateObjectsUsingBlock:^(PhobosSendDataEntity * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [sendDataEntities enumerateObjectsUsingBlock:^(PhobosSendDataEntity * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (temp.count >= PhobosMaxSendCount) { if (temp.count >= PhobosMaxSendCount) {
// 会调用当前方法,但数据规模不会满足 > PhobosMaxSendCount,不会让数据走到下面的发送,拆分完成 会执行return
[self sendDataWithEntities:temp completion:completion]; [self sendDataWithEntities:temp completion:completion];
[temp removeAllObjects]; [temp removeAllObjects];
} }
...@@ -68,14 +73,15 @@ ...@@ -68,14 +73,15 @@
return; return;
} }
NSMutableDictionary *sendDataMap = [NSMutableDictionary new]; NSMutableDictionary *sendDataMap = [NSMutableDictionary new];
// 将相同api的数据合并
[sendDataEntities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) { [sendDataEntities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSMutableArray *sendData = sendDataMap[obj.api] ?: [NSMutableArray new]; NSMutableArray *sendData = sendDataMap[obj.api] ?: [NSMutableArray new];
[sendData addObject:obj]; [sendData addObject:obj];
[sendDataMap setValue:sendData forKey:obj.api]; [sendDataMap setValue:sendData forKey:obj.api];
}]; }];
// 将实体转为待发送数据,取出PhobosSendDataEntity中的data,并发送
[sendDataMap enumerateKeysAndObjectsUsingBlock:^(NSString *api, NSArray<PhobosSendDataEntity *> *entities, BOOL * _Nonnull stop) { [sendDataMap enumerateKeysAndObjectsUsingBlock:^(NSString *api, NSArray<PhobosSendDataEntity *> *entities, BOOL * _Nonnull stop) {
// TODO: 如果数据量过大,
NSMutableArray *sendDatas = [NSMutableArray new]; NSMutableArray *sendDatas = [NSMutableArray new];
[entities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) { [entities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) {
[sendDatas addObject:[obj.data mj_JSONObject]]; [sendDatas addObject:[obj.data mj_JSONObject]];
......
...@@ -96,5 +96,16 @@ typedef void (^SendDataSuccessBlock)(NSInteger code); ...@@ -96,5 +96,16 @@ typedef void (^SendDataSuccessBlock)(NSInteger code);
*/ */
+ (NSString *)MD5String:(NSString *)str; + (NSString *)MD5String:(NSString *)str;
/*!
* @author zhaiguojun, 16-04-21
*
* @brief 把字典和数组转成string
*
* 相当于调用 [NSJSONSerialization dataWithJSONObject:object options:0 error:&error];
* @return 转换后的string
*
* @since 5.9.3
*/
+ (NSString *)convertToJsonString:(id)object;
@end @end
...@@ -468,4 +468,27 @@ ...@@ -468,4 +468,27 @@
return outputString; return outputString;
} }
+ (NSString *)convertToJsonString:(id)object {
NSString *jsonString = @"";
NSError *error;
if (!object) {
NSAssert(0, @"convertToJsonString object 是nil");
return @"";
}
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
options:NSJSONWritingPrettyPrinted
error:&error];
if (!jsonData) {
NSAssert(0, @"convertToJsonString NSJSONSerialization 出现错误");
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
if (jsonString == nil) {
NSAssert(0, @"convertToJsonString jsonString 是nil");
jsonString = @"";
}
return jsonString;
}
@end @end
...@@ -47,36 +47,34 @@ ...@@ -47,36 +47,34 @@
// 适用于链路中页面浏览事件的统计 添加 refererLink 参数 // 适用于链路中页面浏览事件的统计 添加 refererLink 参数
- (void)initRefererLink { - (void)initRefererLink {
if ([self isKindOfClass:[UIViewController class]]) { // 添加 self.referrerLink.count == 0 ,处理referrerLink有值,就不需要初始化,为后期push、UniversalLinks修改referrerLink进行扩展,否则会重新被赋值
if (self.referrerLink.count == 0 && [self isKindOfClass:[UIViewController class]]) {
// 分present与navigation两种情况 // 分present与navigation两种情况
UIViewController *me = (UIViewController *)self; UIViewController *me = (UIViewController *)self;
if (me.isPush.intValue) { // 如果是推送进来的,结果页面的referrerLink 为空数组, 此处添加过滤。 if (me.isPush.intValue) { // 如果是推送进来的,结果页面的referrerLink 为空数组, 此处添加过滤。
objc_setAssociatedObject(self, @selector(referrerLink), @[], OBJC_ASSOCIATION_RETAIN_NONATOMIC); self.referrerLink = @[];
return; } else if (me.presentingViewController != nil) {
}
if (me.presentingViewController != nil) {
// app全局只有一个navigation,发现此时用navigation.topViewController presentViewController时,最终使用的是navigation弹出的 // app全局只有一个navigation,发现此时用navigation.topViewController presentViewController时,最终使用的是navigation弹出的
// 所以此处要判断,如果是navigation弹出,最后还是要定位到topViewController // 所以此处要判断,如果是navigation弹出,最后还是要定位到topViewController
if ([me.presentingViewController isKindOfClass:[UINavigationController class]]) { if ([me.presentingViewController isKindOfClass:[UINavigationController class]]) {
UIViewController *top = ((UINavigationController *)me.presentingViewController).topViewController; UIViewController *top = ((UINavigationController *)me.presentingViewController).topViewController;
NSMutableArray *tempLink = [NSMutableArray arrayWithArray:top.referrerLink]; NSMutableArray *tempLink = [NSMutableArray arrayWithArray:top.referrerLink];
[tempLink addObject:top.pageName]; [tempLink addObject:top.pageName];
objc_setAssociatedObject(self, @selector(referrerLink), tempLink, OBJC_ASSOCIATION_RETAIN_NONATOMIC); self.referrerLink = tempLink;
} else { } else {
NSMutableArray *tempLink = [NSMutableArray arrayWithArray:me.presentingViewController.referrerLink]; NSMutableArray *tempLink = [NSMutableArray arrayWithArray:me.presentingViewController.referrerLink];
[tempLink addObject:me.presentingViewController.pageName]; [tempLink addObject:me.presentingViewController.pageName];
objc_setAssociatedObject(self, @selector(referrerLink), tempLink, OBJC_ASSOCIATION_RETAIN_NONATOMIC); self.referrerLink = tempLink;
} }
} else { } else {
NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers; NSArray *navigationPool = ((UIViewController *)self).navigationController.viewControllers;
NSInteger refererIndex = navigationPool.count - 2; NSInteger refererIndex = navigationPool.count - 2;
if (refererIndex < 0 ) { if (refererIndex >= 0 ) {
return ; UIViewController *controller = navigationPool[refererIndex];
NSMutableArray *tempLink = [NSMutableArray arrayWithArray:controller.referrerLink];
[tempLink addObject:controller.pageName];
self.referrerLink = tempLink;
} }
UIViewController *controller = navigationPool[refererIndex];
NSMutableArray *tempLink = [NSMutableArray arrayWithArray:controller.referrerLink];
[tempLink addObject:controller.pageName];
objc_setAssociatedObject(self, @selector(referrerLink), tempLink, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
} }
} }
} }
...@@ -88,7 +86,7 @@ ...@@ -88,7 +86,7 @@
-(NSArray *)referrerLink { -(NSArray *)referrerLink {
NSArray *referrerLink = objc_getAssociatedObject(self, @selector(referrerLink)); NSArray *referrerLink = objc_getAssociatedObject(self, @selector(referrerLink));
return referrerLink; return referrerLink ?: @[];
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment