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
0e050c9b
Commit
0e050c9b
authored
May 13, 2019
by
乔金柱
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'jql/phobos' into 'master'
PV埋点数据校验+单元测试 See merge request
!36
parents
8ecf643f
c6df8011
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
128 additions
and
4 deletions
+128
-4
WorkspaceSettings.xcsettings
...bos.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
+8
-0
GMViewController.m
Example/GMPhobos/GMViewController.m
+43
-1
Podfile.lock
Example/Podfile.lock
+2
-2
GMPhotoTest.m
Example/Tests/GMPhotoTest.m
+40
-0
Phobos.m
GMPhobos/Classes/Phobos.m
+35
-1
No files found.
Example/GMPhobos.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
0 → 100644
View file @
0e050c9b
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist
version=
"1.0"
>
<dict>
<key>
BuildSystemType
</key>
<string>
Original
</string>
</dict>
</plist>
Example/GMPhobos/GMViewController.m
View file @
0e050c9b
...
...
@@ -8,6 +8,16 @@
#import "GMViewController.h"
#import <GMPhobos/Phobos.h>
@import
GMCache
;
@import
GMPhobos
.
PhobosUtil
;
@import
GMPhobos
.
Phobos
;
#define PhobosCacheKey @"PhobosCacheKey"
NSString
*
const
MockAppName
=
@"gengmei_test"
;
NSString
*
const
MockChannelId
=
@"AppStore"
;
NSString
*
const
MockEventId
=
@"eventId"
;
NSString
*
const
MockUserId
=
@"1"
;
NSString
*
const
MockCityId
=
@"beijing"
;
@interface
GMViewController
()
...
...
@@ -24,8 +34,40 @@
#else
NSString
*
url
=
@"http://log.test.gengmei.cc/log/collect"
;
#endif
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
Phobos
*
phobos
=
[
Phobos
clientWithAppName
:
MockAppName
channelId
:
MockChannelId
];
phobos
.
serverAPI
=
url
;
[
phobos
setLogEnabled
:
NO
];
// 调试打Log模式,看情况开启
phobos
.
signingType
=
PhobosSigningTypeDebug
;
phobos
.
userId
=
@""
;
[
Phobos
setSharedClient
:
phobos
];
NSString
*
inDate
=
[
PhobosUtil
currentTime
];
NSMutableDictionary
*
dict
=
[[
NSMutableDictionary
alloc
]
init
];
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"out"
];
[
dict
setObject
:
inDate
forKey
:
@"in"
];
[
dict
setObject
:
@"test"
forKey
:
@"page_name"
];
[
dict
setObject
:
@""
forKey
:
@"business_id"
];
[
dict
setObject
:
@""
forKey
:
@"referrer"
];
[
dict
setObject
:
@
(
0
)
forKey
:
@"fake"
];
[
dict
setObject
:
@""
forKey
:
@"referrer_id"
];
[
dict
setObject
:
@""
forKey
:
@"extra_param"
];
[
dict
setObject
:
@""
forKey
:
@"referrer_tab_name"
];
[
dict
setObject
:
@
(
0
)
forKey
:
@"is_push"
];
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"in"
];
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"out"
];
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
[
Phobos
track
:
@"test"
attributes
:
dict
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
[
Phobos
sharedClient
].
serverAPI
=
url
;
}
-
(
void
)
didReceiveMemoryWarning
...
...
Example/Podfile.lock
View file @
0e050c9b
...
...
@@ -35,7 +35,7 @@ PODS:
- GMKit/Protocol (0.8.4):
- Masonry (= 1.1.0)
- SDWebImage (= 3.7.6)
- GMPhobos (1.1.
2
):
- GMPhobos (1.1.
6
):
- GMCache (= 0.2.3)
- GMKit
- Masonry (1.1.0)
...
...
@@ -63,7 +63,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
GMCache: 09a3029c96fe130e3a21faef70b3d9d2ce92d639
GMKit: a30da06b84e5c4a357d427c70d1b5ec672a1f6a1
GMPhobos:
5d9b29fb16fb7b8f3b2983aaab8b42cefc510baa
GMPhobos:
cdc1ac3bd8dbc57eb2efe4ac9a7e6ae9d128fc8f
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
...
...
Example/Tests/GMPhotoTest.m
View file @
0e050c9b
...
...
@@ -341,6 +341,46 @@ NSString *const MockCityId = @"beijing";
XCTAssertFalse
(
controller
.
needLogPV
,
@"needLogPV赋值为NO时应该NO"
);
}
-
(
void
)
testCheckPVPhobos
{
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
NSString
*
inDate
=
[
PhobosUtil
currentTime
];
[
NSThread
sleepForTimeInterval
:
1
];
//模拟浏览页面,让out和in时间相差1s
NSMutableDictionary
*
dict
=
[[
NSMutableDictionary
alloc
]
init
];
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"out"
];
[
dict
setObject
:
inDate
forKey
:
@"in"
];
[
dict
setObject
:
@"test"
forKey
:
@"page_name"
];
[
dict
setObject
:
@""
forKey
:
@"business_id"
];
[
dict
setObject
:
@""
forKey
:
@"referrer"
];
[
dict
setObject
:
@
(
0
)
forKey
:
@"fake"
];
[
dict
setObject
:
@""
forKey
:
@"referrer_id"
];
[
dict
setObject
:
@""
forKey
:
@"extra_param"
];
[
dict
setObject
:
@""
forKey
:
@"referrer_tab_name"
];
[
dict
setObject
:
@
(
0
)
forKey
:
@"is_push"
];
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
NSArray
*
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"PhobosCacheKey 下面应该有数据"
);
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
1
,
@"PhobosCacheKey 上条数据不应该发送"
);
[
NSThread
sleepForTimeInterval
:
2
];
//模拟浏览页面,让第二次浏览和上一次时间相差2s
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"in"
];
[
NSThread
sleepForTimeInterval
:
1
];
//模拟浏览页面,让out和in时间相差1s
[
dict
setObject
:[
PhobosUtil
currentTime
]
forKey
:
@"out"
];
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
2
,
@"PhobosCacheKey 上条数据应该发送"
);
[
Phobos
track
:
@"page_view"
attributes
:
dict
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
2
,
@"PhobosCacheKey 上条数据不应该发送"
);
[
Phobos
track
:
@"test"
attributes
:
dict
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
XCTAssertTrue
(
array
.
count
==
3
,
@"PhobosCacheKey 上条数据应该发送"
);
}
#pragma mark - 其它方法test
...
...
GMPhobos/Classes/Phobos.m
View file @
0e050c9b
...
...
@@ -448,8 +448,42 @@ static NSString *sdkVersion = @"110";
NSMutableArray
*
dataArray
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
if
(
dataArray
)
{
#ifdef APPSTORE
[
dataArray
addObject
:
data
];
}
else
{
#else
if
(
data
[
@"type"
]
&&
[
data
[
@"type"
]
isEqualToString
:
@"page_view"
])
{
NSDictionary
*
pageParams
=
data
[
@"params"
];
NSDate
*
pageInTime
=
[
NSDate
dateWithTimeIntervalSince1970
:[
pageParams
[
@"in"
]
longLongValue
]];
NSDate
*
pageOutTime
=
[
NSDate
dateWithTimeIntervalSince1970
:[
pageParams
[
@"out"
]
longLongValue
]];
if
(
pageInTime
&&
pageOutTime
)
{
__block
BOOL
checkTimeError
;
[
dataArray
enumerateObjectsUsingBlock
:
^
(
NSDictionary
*
_Nonnull
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
if
(
obj
[
@"type"
]
&&
[
obj
[
@"type"
]
isEqualToString
:
@"page_view"
])
{
NSDictionary
*
params
=
obj
[
@"params"
];
NSDate
*
objInTime
=
[
NSDate
dateWithTimeIntervalSince1970
:[
params
[
@"in"
]
longLongValue
]];
NSDate
*
objOutTime
=
[
NSDate
dateWithTimeIntervalSince1970
:[
params
[
@"out"
]
longLongValue
]];
if
([
pageInTime
timeIntervalSinceDate
:
objInTime
]
<
1
||
[
pageOutTime
timeIntervalSinceDate
:
objOutTime
]
<
1
)
{
checkTimeError
=
YES
;
stop
=
YES
;
phobosLog
(
@"%s____数据校验失败"
,
__func__
);
#ifndef APPSTORE
UIAlertView
*
alertView
=
[[
UIAlertView
alloc
]
initWithTitle
:
@"PV埋点可能数据异常"
message
:
nil
delegate
:
nil
cancelButtonTitle
:
@"确定"
otherButtonTitles
:
nil
,
nil
];
[
alertView
show
];
#endif
}
}
}];
if
(
!
checkTimeError
)
{
phobosLog
(
@"%s____数据校验成功"
,
__func__
);
[
dataArray
addObject
:
data
];
}
}
}
else
{
[
dataArray
addObject
:
data
];
}
#endif
}
else
{
dataArray
=
[
NSMutableArray
arrayWithObject
:
data
];
}
[
GMCache
storeObjectAtDocumentPathWithkey
:
PhobosCacheKey
object
:
dataArray
];
...
...
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