Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
GMPhobos
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMPhobos
Commits
034a89c8
Commit
034a89c8
authored
Nov 08, 2017
by
汪洋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将存储区改为Document
parent
b0f06ec9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
25 deletions
+28
-25
GMViewController.m
Example/GMPhobos/GMViewController.m
+0
-2
GMPhobosUtilTest.m
Example/Tests/GMPhobosUtilTest.m
+6
-2
GMPhotoTest.m
Example/Tests/GMPhotoTest.m
+7
-7
Phobos.m
Pod/Classes/Phobos.m
+15
-14
No files found.
Example/GMPhobos/GMViewController.m
View file @
034a89c8
...
...
@@ -21,8 +21,6 @@
#ifdef POD_CONFIGURATION_APP_STORE
NSString
*
url
=
@"http://log.gmei.com/log/collect"
;
#elif POD_CONFIGURATION_UNIT_TEST
NSString
*
url
=
@"http://jaguar.gmei/log/collect"
;
#else
NSString
*
url
=
@"http://log.test.gengmei.cc/log/collect"
;
#endif
...
...
Example/Tests/GMPhobosUtilTest.m
View file @
034a89c8
...
...
@@ -8,6 +8,7 @@
#import <XCTest/XCTest.h>
#import "PhobosUtil.h"
@import
GMPhobos
;
@interface
GMPhobosUtilTest
:
XCTestCase
@property
(
nonatomic
,
retain
)
NSMutableArray
*
mockArray
;
...
...
@@ -17,6 +18,9 @@
-
(
void
)
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
];
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
[
_mockArray
addObject
:@{
@"app"
:
@{
@"channel"
:
@"App Store"
,
@"name"
:
@"gengmei_doctor"
,
@"version"
:
@"1.8.0"
},
...
...
@@ -57,7 +61,7 @@
*/
-
(
void
)
testSendDataToMars
{
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
@"Testing Async Method Works!"
];
NSData
*
mockData
=
[
self
encodeAndCompressArray
:
_mockArray
];
[
PhobosUtil
sendData
:
mockData
success
:
^
(
NSInteger
code
)
{
[
expectation
fulfill
];
...
...
@@ -65,7 +69,7 @@
}];
//如果超时,则认为发送失败
[
self
waitForExpectationsWithTimeout
:
3
handler
:
^
(
NSError
*
error
)
{
[
self
waitForExpectationsWithTimeout
:
60
handler
:
^
(
NSError
*
error
)
{
if
(
error
)
{
XCTFail
(
@"Expectation Failed with error: %@"
,
error
);
...
...
Example/Tests/GMPhotoTest.m
View file @
034a89c8
...
...
@@ -36,7 +36,7 @@ NSString *const MockCityId = @"beijing";
-
(
void
)
tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[
super
tearDown
];
[
_cache
removeObjectAtD
isk
Withkey
:
PhobosCacheKey
];
[
_cache
removeObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
}
/**
...
...
@@ -48,7 +48,7 @@ NSString *const MockCityId = @"beijing";
[
_client
setUserId
:
MockUserId
];
[
_client
setCurrentCityId
:
MockCityId
];
[
Phobos
track
:
MockEventId
];
NSArray
*
array
=
[
_cache
fetchObjectAtD
isk
Withkey
:
PhobosCacheKey
];
NSArray
*
array
=
[
_cache
fetchObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
[
self
verfiyDict
:
dict
];
...
...
@@ -62,7 +62,7 @@ NSString *const MockCityId = @"beijing";
*/
-
(
void
)
testTrackEventWithoutAttr
{
[
Phobos
track
:
MockEventId
];
NSArray
*
array
=
[
_cache
fetchObjectAtD
isk
Withkey
:
PhobosCacheKey
];
NSArray
*
array
=
[
_cache
fetchObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
[
self
verfiyDict
:
dict
];
...
...
@@ -77,7 +77,7 @@ NSString *const MockCityId = @"beijing";
-
(
void
)
testTrackEventWithAttr
{
NSDictionary
*
attr
=
@{
@"attr"
:
@"track_attr"
};
[
Phobos
track
:
MockEventId
attributes
:
attr
];
NSArray
*
array
=
[
_cache
fetchObjectAtD
isk
Withkey
:
PhobosCacheKey
];
NSArray
*
array
=
[
_cache
fetchObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"array is empty"
);
NSDictionary
*
dict
=
[
array
objectAtIndex
:
0
];
[
self
verfiyDict
:
dict
];
...
...
@@ -98,7 +98,7 @@ NSString *const MockCityId = @"beijing";
// When
[
Phobos
track
:
MockEventId
attributes
:
attr
sendNow
:
YES
];
// Then
NSArray
*
array
=
[
_cache
fetchObjectAtD
isk
Withkey
:
PhobosCacheKey
];
NSArray
*
array
=
[
_cache
fetchObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
0
,
@"array should be empty"
);
}
...
...
@@ -142,7 +142,7 @@ NSString *const MockCityId = @"beijing";
[
controller
viewWillAppear
:
true
];
[
controller
viewWillDisappear
:
true
];
[
self
paramUnNilCheck
];
NSArray
*
array
=
[[
WMCacheService
sharedInstance
]
fetchObjectAtD
isk
Withkey
:
PhobosCacheKey
];
NSArray
*
array
=
[[
WMCacheService
sharedInstance
]
fetchObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"PhobosCacheKey 下面应该有数据"
);
NSDictionary
*
dic
=
array
[
0
][
@"params"
];
...
...
@@ -156,7 +156,7 @@ NSString *const MockCityId = @"beijing";
}
-
(
void
)
paramUnNilCheck
{
NSArray
*
array
=
[[
WMCacheService
sharedInstance
]
fetchObjectAtD
isk
Withkey
:
PhobosCacheKey
];
NSArray
*
array
=
[[
WMCacheService
sharedInstance
]
fetchObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
!=
0
,
@"PhobosCacheKey 下面应该有数据"
);
NSDictionary
*
dic
=
array
[
0
][
@"params"
];
...
...
Pod/Classes/Phobos.m
View file @
034a89c8
...
...
@@ -108,10 +108,11 @@ static NSString *sdkVersion = @"110";
[
Phobos
track
:
@"device_opened"
attributes
:
dict
sendNow
:
YES
];
/** 第一次打开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
:
NO
];
[
cache
storeObjectAtD
isk
Withkey
:
PhobosHaveOpenApp
object
:
PhobosHaveOpenApp
];
[
cache
storeObjectAtD
ucmentPath
Withkey
:
PhobosHaveOpenApp
object
:
PhobosHaveOpenApp
];
}
}
...
...
@@ -154,7 +155,7 @@ static NSString *sdkVersion = @"110";
_serialId
=
0
;
_sessionId
=
[[
NSUUID
UUID
]
UUIDString
];
WMCacheService
*
cache
=
[
WMCacheService
sharedInstance
];
[
cache
storeObjectAtD
isk
Withkey
:
PhobosBeginTime
object
:[
PhobosUtil
currentTime
]];
[
cache
storeObjectAtD
ucmentPath
Withkey
:
PhobosBeginTime
object
:[
PhobosUtil
currentTime
]];
}
/**
...
...
@@ -201,7 +202,7 @@ static NSString *sdkVersion = @"110";
-
(
void
)
handleSessionOver
{
WMCacheService
*
cache
=
[
WMCacheService
sharedInstance
];
//进入后台的同时,把记录时间同步到服务端,把已使用时间清空
double
beginTime
=
[[
cache
fetchObjectAtD
isk
Withkey
:
PhobosBeginTime
]
doubleValue
];
double
beginTime
=
[[
cache
fetchObjectAtD
ucmentPath
Withkey
:
PhobosBeginTime
]
doubleValue
];
if
(
beginTime
==
0
)
{
return
;
}
...
...
@@ -220,7 +221,7 @@ static NSString *sdkVersion = @"110";
@"build_model"
:
[
UIDevice
deviceVersion
],
};
[
Phobos
track
:
@"on_app_session_over"
attributes
:
dict
];
[
cache
removeObjectAtD
isk
Withkey
:
PhobosBeginTime
];
[
cache
removeObjectAtD
ucmentPath
Withkey
:
PhobosBeginTime
];
//当前session结束之后,把id置为0
_serialId
=
0
;
}
...
...
@@ -252,7 +253,7 @@ static NSString *sdkVersion = @"110";
+
(
void
)
track
:
(
NSString
*
)
eventId
attributes
:
(
NSDictionary
*
)
attributes
{
[
self
track
:
eventId
attributes
:
attributes
sendNow
:
NO
];
NSArray
*
array
=
[[
WMCacheService
sharedInstance
]
fetchObjectAtD
isk
Withkey
:
PhobosCacheKey
];
NSArray
*
array
=
[[
WMCacheService
sharedInstance
]
fetchObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
//超过一定数量的话,统一发送一次
if
(
array
.
count
>
PhobosShardCount
)
{
[
sharedClient
sendArray
:
array
cleanCacheRightNow
:
YES
];
...
...
@@ -398,13 +399,13 @@ static NSString *sdkVersion = @"110";
phobosLog
([
NSString
stringWithFormat
:
@"save dictionary: %@"
,
data
]);
}
WMCacheService
*
cache
=
[
WMCacheService
sharedInstance
];
NSMutableArray
*
dataArray
=
[
cache
fetchObjectAtD
isk
Withkey
:
PhobosCacheKey
];
NSMutableArray
*
dataArray
=
[
cache
fetchObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
if
(
dataArray
)
{
[
dataArray
addObject
:
data
];
}
else
{
dataArray
=
[
NSMutableArray
arrayWithObject
:
data
];
}
[
cache
storeObjectAtD
isk
Withkey
:
PhobosCacheKey
object
:
dataArray
];
[
cache
storeObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
object
:
dataArray
];
}
/**
...
...
@@ -413,7 +414,7 @@ static NSString *sdkVersion = @"110";
* @since 0.0.1
*/
-
(
void
)
fetchDataAndSend
{
NSArray
*
paramsArray
=
[[
WMCacheService
sharedInstance
]
fetchObjectAtD
isk
Withkey
:
PhobosCacheKey
];
NSArray
*
paramsArray
=
[[
WMCacheService
sharedInstance
]
fetchObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
if
(
paramsArray
.
count
>
0
)
{
[
self
sendArray
:
paramsArray
cleanCacheRightNow
:
YES
];
}
...
...
@@ -423,7 +424,7 @@ static NSString *sdkVersion = @"110";
从缓存区获取数据,发给服务器,请求成功的时候,把缓存区的数据删除掉
*/
-
(
void
)
sendArray
{
NSMutableArray
*
dataArray
=
[[
WMCacheService
sharedInstance
]
fetchObjectAtD
isk
Withkey
:
PhobosTempCacheKey
];
NSMutableArray
*
dataArray
=
[[
WMCacheService
sharedInstance
]
fetchObjectAtD
ucmentPath
Withkey
:
PhobosTempCacheKey
];
if
(
_logEnabled
)
{
phobosLog
([
NSString
stringWithFormat
:
@"array prepare to fly --✈: %@"
,
dataArray
]);
}
...
...
@@ -433,7 +434,7 @@ static NSString *sdkVersion = @"110";
if
(
compressedData
)
{
[
PhobosUtil
sendData
:
compressedData
success
:
^
(
NSInteger
code
)
{
phobosLog
(
@"✈ ---------- ✈ data arrived Mars"
);
[[
WMCacheService
sharedInstance
]
removeObjectAtD
isk
Withkey
:
PhobosTempCacheKey
];
[[
WMCacheService
sharedInstance
]
removeObjectAtD
ucmentPath
Withkey
:
PhobosTempCacheKey
];
}];
}
}
...
...
@@ -453,17 +454,17 @@ static NSString *sdkVersion = @"110";
@try
{
//1.获取缓存区的数据,把新数据追加进去
WMCacheService
*
cache
=
[
WMCacheService
sharedInstance
];
NSMutableArray
*
dataArray
=
[
cache
fetchObjectAtD
isk
Withkey
:
PhobosTempCacheKey
];
NSMutableArray
*
dataArray
=
[
cache
fetchObjectAtD
ucmentPath
Withkey
:
PhobosTempCacheKey
];
if
(
dataArray
)
{
[
dataArray
addObjectsFromArray
:
array
];
}
else
{
dataArray
=
[
NSMutableArray
arrayWithArray
:
array
];
}
[
cache
storeObjectAtD
isk
Withkey
:
PhobosTempCacheKey
object
:
dataArray
];
[
cache
storeObjectAtD
ucmentPath
Withkey
:
PhobosTempCacheKey
object
:
dataArray
];
//2.把缓存区的数据发送给服务器
[
self
sendArray
];
//3.把原有的数据删除
[
cache
removeObjectAtD
isk
Withkey
:
PhobosCacheKey
];
[
cache
removeObjectAtD
ucmentPath
Withkey
:
PhobosCacheKey
];
}
@catch
(
NSException
*
exception
)
{
phobosLog
(
exception
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment