Commit efbbe85b authored by 汪洋's avatar 汪洋

升级GMCache

parent a10ace42
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
[Phobos sharedClient].serverAPI = url; [Phobos sharedClient].serverAPI = url;
} }
- (void)didReceiveMemoryWarning - (void)didReceiveMemoryWarning
{ {
[super didReceiveMemoryWarning]; [super didReceiveMemoryWarning];
......
source 'https://github.com/CocoaPods/Specs.git'
source 'git@git.wanmeizhensuo.com:gengmeiios/GMSpecs.git' source 'git@git.wanmeizhensuo.com:gengmeiios/GMSpecs.git'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0' platform :ios, '8.0'
use_frameworks! use_frameworks!
inhibit_all_warnings! inhibit_all_warnings!
...@@ -7,6 +8,7 @@ inhibit_all_warnings! ...@@ -7,6 +8,7 @@ inhibit_all_warnings!
target 'GMPhobos_Example' do target 'GMPhobos_Example' do
pod 'GMPhobos', :path => '../' pod 'GMPhobos', :path => '../'
pod 'GMCache', '0.2.0'
target 'GMPhobos_Tests' do target 'GMPhobos_Tests' do
inherit! :search_paths inherit! :search_paths
end end
......
PODS: PODS:
- GMCache (0.1.2): - GMCache (0.2.0):
- TMCache (~> 2.1.0) - TMCache (= 2.1.0)
- GMKit (0.8.4): - GMKit (0.8.4):
- GMKit/Category (= 0.8.4) - GMKit/Category (= 0.8.4)
- GMKit/Color (= 0.8.4) - GMKit/Color (= 0.8.4)
...@@ -35,7 +35,7 @@ PODS: ...@@ -35,7 +35,7 @@ PODS:
- GMKit/Protocol (0.8.4): - GMKit/Protocol (0.8.4):
- Masonry (= 1.1.0) - Masonry (= 1.1.0)
- SDWebImage (= 3.7.6) - SDWebImage (= 3.7.6)
- GMPhobos (0.5.3): - GMPhobos (0.5.4):
- GMCache - GMCache
- GMKit - GMKit
- Masonry (1.1.0) - Masonry (1.1.0)
...@@ -45,6 +45,7 @@ PODS: ...@@ -45,6 +45,7 @@ PODS:
- TMCache (2.1.0) - TMCache (2.1.0)
DEPENDENCIES: DEPENDENCIES:
- GMCache (= 0.2.0)
- GMPhobos (from `../`) - GMPhobos (from `../`)
EXTERNAL SOURCES: EXTERNAL SOURCES:
...@@ -52,13 +53,13 @@ EXTERNAL SOURCES: ...@@ -52,13 +53,13 @@ EXTERNAL SOURCES:
:path: ../ :path: ../
SPEC CHECKSUMS: SPEC CHECKSUMS:
GMCache: fb0af70b420715ef9519487fdd932a357b3cd8d4 GMCache: b7d48432ee2469eb0c6c86c720a1958bd373187e
GMKit: a30da06b84e5c4a357d427c70d1b5ec672a1f6a1 GMKit: a30da06b84e5c4a357d427c70d1b5ec672a1f6a1
GMPhobos: a6c7419f4ae91aac3c0520902654e96007bdd0d6 GMPhobos: 9549afe9e949fadc2ac54e4bb26cb4c2519cd417
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201 Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9 SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
PODFILE CHECKSUM: 393bbb8ecc2aa3d185a0a793d6ba79e491b7ebd4 PODFILE CHECKSUM: 88bad4cf7811c4caa54519587b95fcc2e18bc404
COCOAPODS: 1.3.1 COCOAPODS: 1.4.0
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
// //
#import "Phobos.h" #import "Phobos.h"
#import <GMCache/GMCache-umbrella.h>
#import <AdSupport/AdSupport.h> #import <AdSupport/AdSupport.h>
#import "PhobosUtil.h" #import "PhobosUtil.h"
#import "PhobosConfig.h" #import "PhobosConfig.h"
...@@ -15,6 +14,7 @@ ...@@ -15,6 +14,7 @@
#import "PhobosUtil.h" #import "PhobosUtil.h"
#import "PhobosCustomVisibleController.h" #import "PhobosCustomVisibleController.h"
#import "UIDevice+Resolutions.h" #import "UIDevice+Resolutions.h"
@import GMCache;
static Phobos *sharedClient = nil; static Phobos *sharedClient = nil;
static NSString *sdkVersion = @"110"; static NSString *sdkVersion = @"110";
...@@ -68,8 +68,7 @@ static NSString *sdkVersion = @"110"; ...@@ -68,8 +68,7 @@ static NSString *sdkVersion = @"110";
* disk下的PhobosHaveOpenApp只要存在,就把他取出来放到document下(注:当不支持7.6.16版本的时候,干掉这个方法) * disk下的PhobosHaveOpenApp只要存在,就把他取出来放到document下(注:当不支持7.6.16版本的时候,干掉这个方法)
*/ */
- (void)synchronizePhobosKey { - (void)synchronizePhobosKey {
WMCacheService *cache = [WMCacheService sharedInstance]; if ([GMCache fetchObjectAtDiskWithkey:PhobosHaveOpenApp]) {
if ([cache fetchObjectAtDiskWithkey:PhobosHaveOpenApp]) {
NSString *prefePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *prefePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
prefePath = [NSString stringWithFormat:@"%@/com.tumblr.TMDiskCache.WMCacheShared/%@",prefePath ,PhobosHaveOpenApp]; prefePath = [NSString stringWithFormat:@"%@/com.tumblr.TMDiskCache.WMCacheShared/%@",prefePath ,PhobosHaveOpenApp];
NSURL *fileUrl = [NSURL fileURLWithPathComponents:@[prefePath]]; NSURL *fileUrl = [NSURL fileURLWithPathComponents:@[prefePath]];
...@@ -106,7 +105,7 @@ static NSString *sdkVersion = @"110"; ...@@ -106,7 +105,7 @@ static NSString *sdkVersion = @"110";
在APP启动、从后台到前台的时候需要记录device_opened埋点 在APP启动、从后台到前台的时候需要记录device_opened埋点
*/ */
- (void)handleEventDeviceOpened{ - (void)handleEventDeviceOpened{
WMCacheService *cache = [WMCacheService sharedInstance];
/** 每次打开APP埋点 **/ /** 每次打开APP埋点 **/
NSDictionary *dict = @{@"build_cpu_abi": [PhobosUtil currentDeviceCPUType], NSDictionary *dict = @{@"build_cpu_abi": [PhobosUtil currentDeviceCPUType],
@"cpu_count": [PhobosUtil currentDeviceCPUCount], @"cpu_count": [PhobosUtil currentDeviceCPUCount],
...@@ -122,10 +121,10 @@ static NSString *sdkVersion = @"110"; ...@@ -122,10 +121,10 @@ static NSString *sdkVersion = @"110";
/** 第一次打开APP埋点 **/ /** 第一次打开APP埋点 **/
// 当不再支持7.6.15版本时,只保留 // 当不再支持7.6.15版本时,只保留
if (![cache fetchObjectAtDucmentPathWithkey:PhobosHaveOpenApp]) { if (![GMCache 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 storeObjectAtDucmentPathWithkey:PhobosHaveOpenApp object:PhobosHaveOpenApp]; [GMCache storeObjectAtDucmentPathWithkey:PhobosHaveOpenApp object:PhobosHaveOpenApp];
} }
} }
...@@ -159,8 +158,8 @@ static NSString *sdkVersion = @"110"; ...@@ -159,8 +158,8 @@ static NSString *sdkVersion = @"110";
- (void)handleSessionStart{ - (void)handleSessionStart{
_serialId = 0; _serialId = 0;
_sessionId = [[NSUUID UUID] UUIDString]; _sessionId = [[NSUUID UUID] UUIDString];
WMCacheService *cache = [WMCacheService sharedInstance];
[cache storeObjectAtDucmentPathWithkey:PhobosBeginTime object:[PhobosUtil currentTime]]; [GMCache storeObjectAtDucmentPathWithkey:PhobosBeginTime object:[PhobosUtil currentTime]];
} }
/** /**
...@@ -205,9 +204,9 @@ static NSString *sdkVersion = @"110"; ...@@ -205,9 +204,9 @@ static NSString *sdkVersion = @"110";
* @since 0.0.1 * @since 0.0.1
*/ */
- (void)handleSessionOver{ - (void)handleSessionOver{
WMCacheService *cache = [WMCacheService sharedInstance];
//进入后台的同时,把记录时间同步到服务端,把已使用时间清空 //进入后台的同时,把记录时间同步到服务端,把已使用时间清空
double beginTime = [[cache fetchObjectAtDucmentPathWithkey:PhobosBeginTime] doubleValue]; double beginTime = [[GMCache fetchObjectAtDucmentPathWithkey:PhobosBeginTime] doubleValue];
if (beginTime == 0) { if (beginTime == 0) {
return; return;
} }
...@@ -226,7 +225,7 @@ static NSString *sdkVersion = @"110"; ...@@ -226,7 +225,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 removeObjectAtDucmentPathWithkey:PhobosBeginTime]; [GMCache removeObjectAtDucmentPathWithkey:PhobosBeginTime];
//当前session结束之后,把id置为0 //当前session结束之后,把id置为0
_serialId = 0; _serialId = 0;
} }
...@@ -258,7 +257,7 @@ static NSString *sdkVersion = @"110"; ...@@ -258,7 +257,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] fetchObjectAtDucmentPathWithkey:PhobosCacheKey]; NSArray *array = [GMCache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
//超过一定数量的话,统一发送一次 //超过一定数量的话,统一发送一次
if (array.count > PhobosShardCount) { if (array.count > PhobosShardCount) {
[sharedClient sendArray:array cleanCacheRightNow:YES]; [sharedClient sendArray:array cleanCacheRightNow:YES];
...@@ -403,14 +402,14 @@ static NSString *sdkVersion = @"110"; ...@@ -403,14 +402,14 @@ static NSString *sdkVersion = @"110";
if (_logEnabled) { if (_logEnabled) {
phobosLog([NSString stringWithFormat:@"save dictionary: %@",data]); phobosLog([NSString stringWithFormat:@"save dictionary: %@",data]);
} }
WMCacheService *cache = [WMCacheService sharedInstance];
NSMutableArray *dataArray = [cache fetchObjectAtDucmentPathWithkey:PhobosCacheKey]; NSMutableArray *dataArray = [GMCache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
if (dataArray) { if (dataArray) {
[dataArray addObject:data]; [dataArray addObject:data];
}else{ }else{
dataArray = [NSMutableArray arrayWithObject:data]; dataArray = [NSMutableArray arrayWithObject:data];
} }
[cache storeObjectAtDucmentPathWithkey:PhobosCacheKey object:dataArray]; [GMCache storeObjectAtDucmentPathWithkey:PhobosCacheKey object:dataArray];
} }
/** /**
...@@ -419,7 +418,7 @@ static NSString *sdkVersion = @"110"; ...@@ -419,7 +418,7 @@ static NSString *sdkVersion = @"110";
* @since 0.0.1 * @since 0.0.1
*/ */
- (void)fetchDataAndSend{ - (void)fetchDataAndSend{
NSArray *paramsArray = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosCacheKey]; NSArray *paramsArray = [GMCache fetchObjectAtDucmentPathWithkey:PhobosCacheKey];
if (paramsArray.count>0) { if (paramsArray.count>0) {
[self sendArray:paramsArray cleanCacheRightNow:YES]; [self sendArray:paramsArray cleanCacheRightNow:YES];
} }
...@@ -429,7 +428,7 @@ static NSString *sdkVersion = @"110"; ...@@ -429,7 +428,7 @@ static NSString *sdkVersion = @"110";
从缓存区获取数据,发给服务器,请求成功的时候,把缓存区的数据删除掉 从缓存区获取数据,发给服务器,请求成功的时候,把缓存区的数据删除掉
*/ */
- (void)sendArray { - (void)sendArray {
NSMutableArray *dataArray = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:PhobosTempCacheKey]; NSMutableArray *dataArray = [GMCache fetchObjectAtDucmentPathWithkey:PhobosTempCacheKey];
if (_logEnabled) { if (_logEnabled) {
NSData *data = [NSJSONSerialization dataWithJSONObject:dataArray options:NSJSONWritingPrettyPrinted error:nil]; NSData *data = [NSJSONSerialization dataWithJSONObject:dataArray options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
...@@ -441,7 +440,7 @@ static NSString *sdkVersion = @"110"; ...@@ -441,7 +440,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] removeObjectAtDucmentPathWithkey:PhobosTempCacheKey]; [GMCache removeObjectAtDucmentPathWithkey:PhobosTempCacheKey];
}]; }];
} }
} }
...@@ -460,18 +459,18 @@ static NSString *sdkVersion = @"110"; ...@@ -460,18 +459,18 @@ static NSString *sdkVersion = @"110";
- (void)sendArray:(NSArray *)array cleanCacheRightNow:(BOOL)clean { - (void)sendArray:(NSArray *)array cleanCacheRightNow:(BOOL)clean {
@try { @try {
//1.获取缓存区的数据,把新数据追加进去 //1.获取缓存区的数据,把新数据追加进去
WMCacheService *cache = [WMCacheService sharedInstance];
NSMutableArray *dataArray = [cache fetchObjectAtDucmentPathWithkey:PhobosTempCacheKey]; NSMutableArray *dataArray = [GMCache fetchObjectAtDucmentPathWithkey:PhobosTempCacheKey];
if (dataArray) { if (dataArray) {
[dataArray addObjectsFromArray:array]; [dataArray addObjectsFromArray:array];
}else{ }else{
dataArray = [NSMutableArray arrayWithArray:array]; dataArray = [NSMutableArray arrayWithArray:array];
} }
[cache storeObjectAtDucmentPathWithkey:PhobosTempCacheKey object:dataArray]; [GMCache storeObjectAtDucmentPathWithkey:PhobosTempCacheKey object:dataArray];
//2.把缓存区的数据发送给服务器 //2.把缓存区的数据发送给服务器
[self sendArray]; [self sendArray];
//3.把原有的数据删除 //3.把原有的数据删除
[cache removeObjectAtDucmentPathWithkey:PhobosCacheKey]; [GMCache removeObjectAtDucmentPathWithkey:PhobosCacheKey];
} }
@catch (NSException *exception) { @catch (NSException *exception) {
phobosLog(exception); phobosLog(exception);
......
...@@ -53,7 +53,7 @@ WMUser *user = [[WMLoginManager shareInstance] user]; ...@@ -53,7 +53,7 @@ WMUser *user = [[WMLoginManager shareInstance] user];
``` ```
If you would like to use Phobos, you must set the currentCityId that is used with the -[setCurrentCityId:] Instance method. If you would like to use Phobos, you must set the currentCityId that is used with the -[setCurrentCityId:] Instance method.
```objc ```objc
WMCityObject *city = [[WMCacheService sharedInstance] fetchObjectAtDucmentPathWithkey:kCurrentCity]; WMCityObject *city = [GMCache fetchObjectAtDucmentPathWithkey:kCurrentCity];
if (city) { if (city) {
[client setCurrentCityId:city.id]; [client setCurrentCityId:city.id];
} }
...@@ -81,4 +81,4 @@ Guojun Zhai and Thierry Xing ...@@ -81,4 +81,4 @@ Guojun Zhai and Thierry Xing
## License ## License
GMPhobos is available under the MIT license. See the LICENSE file for more info. GMPhobos is available under the MIT license. See the LICENSE file for more info.
\ No newline at end of file
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