Commit 4e67fd77 authored by 井庆林's avatar 井庆林

埋点库修改参数为空问题

parent 503cf24d
...@@ -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);
......
...@@ -139,79 +139,89 @@ static BOOL isGray = NO; ...@@ -139,79 +139,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 */
...@@ -27,9 +27,12 @@ typedef NS_ENUM(NSInteger, PhobosDataSendStatus) { ...@@ -27,9 +27,12 @@ typedef NS_ENUM(NSInteger, PhobosDataSendStatus) {
+ (NSUInteger)fetchCountOfEntitiesWithPredicate:(NSPredicate *)searchFilter; + (NSUInteger)fetchCountOfEntitiesWithPredicate:(NSPredicate *)searchFilter;
+ (void)insertData:(NSDictionary *)data sendAPI:(NSString *)sendAPI; + (void)insertData:(NSDictionary *)data sendAPI:(NSString *)sendAPI;
+ (void)insertData:(NSDictionary *)data sendAPI:(NSString *)sendAPI completion:(MRSaveCompletionHandler)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;
......
...@@ -38,6 +38,10 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -38,6 +38,10 @@ static NSManagedObjectContext *Phobos_defaultContext;
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 +64,10 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -60,6 +64,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 +76,19 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -68,15 +76,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 +97,17 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -85,13 +97,17 @@ 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];
}
+ (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;
......
...@@ -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,33 @@ ...@@ -47,36 +47,33 @@
// 适用于链路中页面浏览事件的统计 添加 refererLink 参数 // 适用于链路中页面浏览事件的统计 添加 refererLink 参数
- (void)initRefererLink { - (void)initRefererLink {
if ([self isKindOfClass:[UIViewController class]]) { 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]; UIViewController *controller = navigationPool[refererIndex];
NSMutableArray *tempLink = [NSMutableArray arrayWithArray:controller.referrerLink]; NSMutableArray *tempLink = [NSMutableArray arrayWithArray:controller.referrerLink];
[tempLink addObject:controller.pageName]; [tempLink addObject:controller.pageName];
objc_setAssociatedObject(self, @selector(referrerLink), tempLink, OBJC_ASSOCIATION_RETAIN_NONATOMIC); self.referrerLink = tempLink;
}
} }
} }
} }
...@@ -88,7 +85,7 @@ ...@@ -88,7 +85,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