Commit 034a89c8 authored by 汪洋's avatar 汪洋

将存储区改为Document

parent b0f06ec9
...@@ -21,8 +21,6 @@ ...@@ -21,8 +21,6 @@
#ifdef POD_CONFIGURATION_APP_STORE #ifdef POD_CONFIGURATION_APP_STORE
NSString *url = @"http://log.gmei.com/log/collect"; NSString *url = @"http://log.gmei.com/log/collect";
#elif POD_CONFIGURATION_UNIT_TEST
NSString *url = @"http://jaguar.gmei/log/collect";
#else #else
NSString *url = @"http://log.test.gengmei.cc/log/collect"; NSString *url = @"http://log.test.gengmei.cc/log/collect";
#endif #endif
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import "PhobosUtil.h" #import "PhobosUtil.h"
@import GMPhobos;
@interface GMPhobosUtilTest : XCTestCase @interface GMPhobosUtilTest : XCTestCase
@property (nonatomic, retain) NSMutableArray *mockArray; @property (nonatomic, retain) NSMutableArray *mockArray;
...@@ -17,6 +18,9 @@ ...@@ -17,6 +18,9 @@
- (void)setUp { - (void)setUp {
[super setUp]; [super setUp];
NSString *url = @"http://log.test.gengmei.cc/log/collect";
[Phobos setSharedClient:[Phobos clientWithAppName:@"gengmei_test" channelId:@"AppStore"]];
[Phobos sharedClient].serverAPI = url;
_mockArray = [[NSMutableArray alloc] init]; _mockArray = [[NSMutableArray alloc] init];
for (int i=0; i<50; i++) { for (int i=0; i<50; i++) {
[_mockArray addObject:@{@"app":@{@"channel":@"App Store",@"name":@"gengmei_doctor",@"version":@"1.8.0"}, [_mockArray addObject:@{@"app":@{@"channel":@"App Store",@"name":@"gengmei_doctor",@"version":@"1.8.0"},
...@@ -57,7 +61,7 @@ ...@@ -57,7 +61,7 @@
*/ */
- (void)testSendDataToMars{ - (void)testSendDataToMars{
XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method Works!"]; XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method Works!"];
NSData *mockData = [self encodeAndCompressArray:_mockArray]; NSData *mockData = [self encodeAndCompressArray:_mockArray];
[PhobosUtil sendData:mockData success:^(NSInteger code) { [PhobosUtil sendData:mockData success:^(NSInteger code) {
[expectation fulfill]; [expectation fulfill];
...@@ -65,7 +69,7 @@ ...@@ -65,7 +69,7 @@
}]; }];
//如果超时,则认为发送失败 //如果超时,则认为发送失败
[self waitForExpectationsWithTimeout:3 handler:^(NSError *error) { [self waitForExpectationsWithTimeout:60 handler:^(NSError *error) {
if(error) if(error)
{ {
XCTFail(@"Expectation Failed with error: %@", error); XCTFail(@"Expectation Failed with error: %@", error);
......
...@@ -36,7 +36,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -36,7 +36,7 @@ NSString *const MockCityId = @"beijing";
- (void)tearDown { - (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class. // Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown]; [super tearDown];
[_cache removeObjectAtDiskWithkey:PhobosCacheKey]; [_cache removeObjectAtDucmentPathWithkey:PhobosCacheKey];
} }
/** /**
...@@ -48,7 +48,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -48,7 +48,7 @@ NSString *const MockCityId = @"beijing";
[_client setUserId:MockUserId]; [_client setUserId:MockUserId];
[_client setCurrentCityId:MockCityId]; [_client setCurrentCityId:MockCityId];
[Phobos track:MockEventId]; [Phobos track:MockEventId];
NSArray *array = [_cache fetchObjectAtDiskWithkey:PhobosCacheKey]; NSArray *array = [_cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 1, @"array is empty"); XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0]; NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict]; [self verfiyDict:dict];
...@@ -62,7 +62,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -62,7 +62,7 @@ NSString *const MockCityId = @"beijing";
*/ */
- (void)testTrackEventWithoutAttr{ - (void)testTrackEventWithoutAttr{
[Phobos track:MockEventId]; [Phobos track:MockEventId];
NSArray *array = [_cache fetchObjectAtDiskWithkey:PhobosCacheKey]; NSArray *array = [_cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 1, @"array is empty"); XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0]; NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict]; [self verfiyDict:dict];
...@@ -77,7 +77,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -77,7 +77,7 @@ NSString *const MockCityId = @"beijing";
- (void)testTrackEventWithAttr{ - (void)testTrackEventWithAttr{
NSDictionary *attr = @{@"attr":@"track_attr"}; NSDictionary *attr = @{@"attr":@"track_attr"};
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
NSArray *array = [_cache fetchObjectAtDiskWithkey:PhobosCacheKey]; NSArray *array = [_cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 1, @"array is empty"); XCTAssertTrue(array.count == 1, @"array is empty");
NSDictionary *dict = [array objectAtIndex:0]; NSDictionary *dict = [array objectAtIndex:0];
[self verfiyDict:dict]; [self verfiyDict:dict];
...@@ -98,7 +98,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -98,7 +98,7 @@ NSString *const MockCityId = @"beijing";
// When // When
[Phobos track:MockEventId attributes:attr sendNow:YES]; [Phobos track:MockEventId attributes:attr sendNow:YES];
// Then // Then
NSArray *array = [_cache fetchObjectAtDiskWithkey:PhobosCacheKey]; NSArray *array = [_cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count == 0, @"array should be empty"); XCTAssertTrue(array.count == 0, @"array should be empty");
} }
...@@ -142,7 +142,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -142,7 +142,7 @@ NSString *const MockCityId = @"beijing";
[controller viewWillAppear:true]; [controller viewWillAppear:true];
[controller viewWillDisappear:true]; [controller viewWillDisappear:true];
[self paramUnNilCheck]; [self paramUnNilCheck];
NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosCacheKey]; NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据"); XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据");
NSDictionary *dic = array[0][@"params"]; NSDictionary *dic = array[0][@"params"];
...@@ -156,7 +156,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -156,7 +156,7 @@ NSString *const MockCityId = @"beijing";
} }
- (void)paramUnNilCheck { - (void)paramUnNilCheck {
NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosCacheKey]; NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据"); XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据");
NSDictionary *dic = array[0][@"params"]; NSDictionary *dic = array[0][@"params"];
......
...@@ -108,10 +108,11 @@ static NSString *sdkVersion = @"110"; ...@@ -108,10 +108,11 @@ static NSString *sdkVersion = @"110";
[Phobos track:@"device_opened" attributes:dict sendNow:YES]; [Phobos track:@"device_opened" attributes:dict sendNow:YES];
/** 第一次打开APP埋点 **/ /** 第一次打开APP埋点 **/
if (![cache fetchObjectAtDiskWithkey:PhobosHaveOpenApp]) { // 当不再支持7.6.15版本时,只保留
if (![cache fetchObjectAtDiskWithkey:PhobosHaveOpenApp] || ![cache fetchObjectAtDucmentPathWithkey:PhobosHaveOpenApp]) {
[Phobos track:@"device_activated" attributes:@{} sendNow:YES]; [Phobos track:@"device_activated" attributes:@{} sendNow:YES];
[Phobos track:@"device_activated" attributes:@{} sendNow:NO]; [Phobos track:@"device_activated" attributes:@{} sendNow:NO];
[cache storeObjectAtDiskWithkey:PhobosHaveOpenApp object:PhobosHaveOpenApp]; [cache storeObjectAtDucmentPathWithkey:PhobosHaveOpenApp object:PhobosHaveOpenApp];
} }
} }
...@@ -154,7 +155,7 @@ static NSString *sdkVersion = @"110"; ...@@ -154,7 +155,7 @@ static NSString *sdkVersion = @"110";
_serialId = 0; _serialId = 0;
_sessionId = [[NSUUID UUID] UUIDString]; _sessionId = [[NSUUID UUID] UUIDString];
WMCacheService *cache = [WMCacheService sharedInstance]; WMCacheService *cache = [WMCacheService sharedInstance];
[cache storeObjectAtDiskWithkey:PhobosBeginTime object:[PhobosUtil currentTime]]; [cache storeObjectAtDucmentPathWithkey:PhobosBeginTime object:[PhobosUtil currentTime]];
} }
/** /**
...@@ -201,7 +202,7 @@ static NSString *sdkVersion = @"110"; ...@@ -201,7 +202,7 @@ static NSString *sdkVersion = @"110";
- (void)handleSessionOver{ - (void)handleSessionOver{
WMCacheService *cache = [WMCacheService sharedInstance]; WMCacheService *cache = [WMCacheService sharedInstance];
//进入后台的同时,把记录时间同步到服务端,把已使用时间清空 //进入后台的同时,把记录时间同步到服务端,把已使用时间清空
double beginTime = [[cache fetchObjectAtDiskWithkey:PhobosBeginTime] doubleValue]; double beginTime = [[cache fetchObjectAtDucmentPathWithkey:PhobosBeginTime] doubleValue];
if (beginTime == 0) { if (beginTime == 0) {
return; return;
} }
...@@ -220,7 +221,7 @@ static NSString *sdkVersion = @"110"; ...@@ -220,7 +221,7 @@ static NSString *sdkVersion = @"110";
@"build_model": [UIDevice deviceVersion], @"build_model": [UIDevice deviceVersion],
}; };
[Phobos track:@"on_app_session_over" attributes:dict]; [Phobos track:@"on_app_session_over" attributes:dict];
[cache removeObjectAtDiskWithkey:PhobosBeginTime]; [cache removeObjectAtDucmentPathWithkey:PhobosBeginTime];
//当前session结束之后,把id置为0 //当前session结束之后,把id置为0
_serialId = 0; _serialId = 0;
} }
...@@ -252,7 +253,7 @@ static NSString *sdkVersion = @"110"; ...@@ -252,7 +253,7 @@ static NSString *sdkVersion = @"110";
+ (void)track:(NSString *)eventId attributes:(NSDictionary *)attributes{ + (void)track:(NSString *)eventId attributes:(NSDictionary *)attributes{
[self track:eventId attributes:attributes sendNow:NO]; [self track:eventId attributes:attributes sendNow:NO];
NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosCacheKey]; NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
//超过一定数量的话,统一发送一次 //超过一定数量的话,统一发送一次
if (array.count > PhobosShardCount) { if (array.count > PhobosShardCount) {
[sharedClient sendArray:array cleanCacheRightNow:YES]; [sharedClient sendArray:array cleanCacheRightNow:YES];
...@@ -398,13 +399,13 @@ static NSString *sdkVersion = @"110"; ...@@ -398,13 +399,13 @@ static NSString *sdkVersion = @"110";
phobosLog([NSString stringWithFormat:@"save dictionary: %@",data]); phobosLog([NSString stringWithFormat:@"save dictionary: %@",data]);
} }
WMCacheService *cache = [WMCacheService sharedInstance]; WMCacheService *cache = [WMCacheService sharedInstance];
NSMutableArray *dataArray = [cache fetchObjectAtDiskWithkey:PhobosCacheKey]; NSMutableArray *dataArray = [cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
if (dataArray) { if (dataArray) {
[dataArray addObject:data]; [dataArray addObject:data];
}else{ }else{
dataArray = [NSMutableArray arrayWithObject:data]; dataArray = [NSMutableArray arrayWithObject:data];
} }
[cache storeObjectAtDiskWithkey:PhobosCacheKey object:dataArray]; [cache storeObjectAtDucmentPathWithkey:PhobosCacheKey object:dataArray];
} }
/** /**
...@@ -413,7 +414,7 @@ static NSString *sdkVersion = @"110"; ...@@ -413,7 +414,7 @@ static NSString *sdkVersion = @"110";
* @since 0.0.1 * @since 0.0.1
*/ */
- (void)fetchDataAndSend{ - (void)fetchDataAndSend{
NSArray *paramsArray = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosCacheKey]; NSArray *paramsArray = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
if (paramsArray.count>0) { if (paramsArray.count>0) {
[self sendArray:paramsArray cleanCacheRightNow:YES]; [self sendArray:paramsArray cleanCacheRightNow:YES];
} }
...@@ -423,7 +424,7 @@ static NSString *sdkVersion = @"110"; ...@@ -423,7 +424,7 @@ static NSString *sdkVersion = @"110";
从缓存区获取数据,发给服务器,请求成功的时候,把缓存区的数据删除掉 从缓存区获取数据,发给服务器,请求成功的时候,把缓存区的数据删除掉
*/ */
- (void)sendArray { - (void)sendArray {
NSMutableArray *dataArray = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosTempCacheKey]; NSMutableArray *dataArray = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosTempCacheKey];
if (_logEnabled) { if (_logEnabled) {
phobosLog([NSString stringWithFormat:@"array prepare to fly --✈: %@",dataArray]); phobosLog([NSString stringWithFormat:@"array prepare to fly --✈: %@",dataArray]);
} }
...@@ -433,7 +434,7 @@ static NSString *sdkVersion = @"110"; ...@@ -433,7 +434,7 @@ static NSString *sdkVersion = @"110";
if (compressedData) { if (compressedData) {
[PhobosUtil sendData:compressedData success:^(NSInteger code) { [PhobosUtil sendData:compressedData success:^(NSInteger code) {
phobosLog(@"✈ ---------- ✈ data arrived Mars"); phobosLog(@"✈ ---------- ✈ data arrived Mars");
[[WMCacheService sharedInstance] removeObjectAtDiskWithkey:PhobosTempCacheKey]; [[WMCacheService sharedInstance] removeObjectAtDucmentPathWithkey:PhobosTempCacheKey];
}]; }];
} }
} }
...@@ -453,17 +454,17 @@ static NSString *sdkVersion = @"110"; ...@@ -453,17 +454,17 @@ static NSString *sdkVersion = @"110";
@try { @try {
//1.获取缓存区的数据,把新数据追加进去 //1.获取缓存区的数据,把新数据追加进去
WMCacheService *cache = [WMCacheService sharedInstance]; WMCacheService *cache = [WMCacheService sharedInstance];
NSMutableArray *dataArray = [cache fetchObjectAtDiskWithkey:PhobosTempCacheKey]; NSMutableArray *dataArray = [cache fetchObjectAtDucmentPathWithkey:PhobosTempCacheKey];
if (dataArray) { if (dataArray) {
[dataArray addObjectsFromArray:array]; [dataArray addObjectsFromArray:array];
}else{ }else{
dataArray = [NSMutableArray arrayWithArray:array]; dataArray = [NSMutableArray arrayWithArray:array];
} }
[cache storeObjectAtDiskWithkey:PhobosTempCacheKey object:dataArray]; [cache storeObjectAtDucmentPathWithkey:PhobosTempCacheKey object:dataArray];
//2.把缓存区的数据发送给服务器 //2.把缓存区的数据发送给服务器
[self sendArray]; [self sendArray];
//3.把原有的数据删除 //3.把原有的数据删除
[cache removeObjectAtDiskWithkey:PhobosCacheKey]; [cache removeObjectAtDucmentPathWithkey:PhobosCacheKey];
} }
@catch (NSException *exception) { @catch (NSException *exception) {
phobosLog(exception); phobosLog(exception);
......
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