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
ffca9286
Commit
ffca9286
authored
Apr 07, 2020
by
井庆林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加注释
parent
4e67fd77
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
3 deletions
+52
-3
Phobos.m
GMPhobos/Classes/Phobos.m
+4
-0
PhobosDataManager.h
GMPhobos/Classes/PhobosDataManager.h
+29
-1
PhobosDataManager.m
GMPhobos/Classes/PhobosDataManager.m
+8
-0
PhobosSendManager.h
GMPhobos/Classes/PhobosSendManager.h
+3
-1
PhobosSendManager.m
GMPhobos/Classes/PhobosSendManager.m
+7
-1
UIResponder+PhobosPV.m
GMPhobos/Classes/UIResponder+PhobosPV.m
+1
-0
No files found.
GMPhobos/Classes/Phobos.m
View file @
ffca9286
...
...
@@ -138,6 +138,10 @@ static BOOL isGray = NO;
[
_oldPhobos
onPVEnd
:
page
];
}
/**
* 添加当前对象的成员变量的赋值,防止外部访问该数据,导致为nil,下同
*/
-
(
void
)
setCaptureNullExpection
:
(
void
(
^
)(
NSString
*
_Nonnull
,
NSDictionary
*
_Nonnull
))
captureNullExpection
{
_captureNullExpection
=
captureNullExpection
;
_rePhobos
.
captureNullExpection
=
captureNullExpection
;
...
...
GMPhobos/Classes/PhobosDataManager.h
View file @
ffca9286
...
...
@@ -22,17 +22,45 @@ typedef NS_ENUM(NSInteger, PhobosDataSendStatus) {
/** 获取待发送数据,包含待发送数据和发送失败数据 */
+
(
NSArray
<
PhobosSendDataEntity
*>
*
)
fetchToBeSendDataEntities
;
/**
* 通过 searchFilter 获取数据
*/
+
(
NSArray
<
PhobosSendDataEntity
*>
*
)
fetchDataEntitiesWithPredicate
:(
NSPredicate
*
)
searchFilter
;
/**
* 获取待发送和发送失败的数据数量
*/
+
(
NSUInteger
)
fetchCountOfToBeSendEntities
;
/**
* 通过 searchFilter 获取数据数量
*/
+
(
NSUInteger
)
fetchCountOfEntitiesWithPredicate
:(
NSPredicate
*
)
searchFilter
;
/**
* 插入埋点数据
* data 埋点参数
* sendAPI 数据接收的服务器API
* completion 插入数据库成功后的回调方法,在保存完成后调用的完成块。如果发生错误,块将以“BOOL”和“NSError”实例的形式传递成功状态。总是在主队列上调用。
* 该方法调用完成,fetch方法获取相应的数据就可获取到,不需要等completion回调。
*/
+
(
void
)
insertData
:(
NSDictionary
*
)
data
sendAPI
:(
NSString
*
)
sendAPI
;
+
(
void
)
insertData
:(
NSDictionary
*
)
data
sendAPI
:(
NSString
*
)
sendAPI
completion
:(
MRSaveCompletionHandler
)
completion
;
/**
* 修改埋点数据
* entities 需要修改的实体
* sendStatus 需要修改为的状态,
* completion 插入数据库成功后的回调方法,在保存完成后调用的完成块。如果发生错误,块将以“BOOL”和“NSError”实例的形式传递成功状态。总是在主队列上调用。
* 该方法调用完成,fetch方法获取相应的数据就可获取到,不需要等completion回调。
*/
+
(
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
)
deleteAllEntities
;
...
...
GMPhobos/Classes/PhobosDataManager.m
View file @
ffca9286
...
...
@@ -19,8 +19,10 @@ static NSManagedObjectContext *Phobos_defaultContext;
+
(
void
)
initialize
{
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
// 创建 NSManagedObjectContext,供埋点库访问CoreData库使用
Phobos_defaultContext
=
[[
NSManagedObjectContext
alloc
]
initWithConcurrencyType
:
NSMainQueueConcurrencyType
];
NSBundle
*
bundle
=
[
NSBundle
bundleForClass
:[
self
class
]];
// 获取埋点数据的实体
NSURL
*
modelURL
=
[
bundle
URLForResource
:
@"GMPhobosData"
withExtension
:
@"momd"
];
NSManagedObjectModel
*
model
=
[[
NSManagedObjectModel
alloc
]
initWithContentsOfURL
:
modelURL
];
...
...
@@ -33,12 +35,15 @@ static NSManagedObjectContext *Phobos_defaultContext;
[
coordinator
addPersistentStoreWithType
:
NSSQLiteStoreType
configuration
:
nil
URL
:
[
NSURL
fileURLWithPath
:
dataPath
]
options
:
nil
error
:
nil
];
// 设置storeCoordinator
Phobos_defaultContext
.
persistentStoreCoordinator
=
coordinator
;
/** 将上次没有获取到发送结果的数据的状态修改为发送失败,待下次重新发送 */
NSPredicate
*
predicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d"
,
PhobosDataSendStatusSending
];
NSArray
<
PhobosSendDataEntity
*>
*
entities
=
[
self
fetchDataEntitiesWithPredicate
:
predicate
];
[
self
updateDataEntities
:
entities
sendStatus
:
PhobosDataSendStatusError
];
/** 将发送成功的数据删除 */
NSPredicate
*
finishPredicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d"
,
PhobosDataSendStatusFinish
];
NSArray
<
PhobosSendDataEntity
*>
*
finishEntities
=
[
self
fetchDataEntitiesWithPredicate
:
finishPredicate
];
[
self
deleteDataEntities
:
finishEntities
];
...
...
@@ -106,6 +111,9 @@ static NSManagedObjectContext *Phobos_defaultContext;
[
self
saveWithCompletion
:
nil
];
}
/**
* 在保存完成后调用的完成块。如果发生错误,块将以“BOOL”和“NSError”实例的形式传递成功状态。总是在主队列上调用。
*/
+
(
void
)
saveWithCompletion
:
(
MRSaveCompletionHandler
)
completion
{
[
Phobos_defaultContext
MR_saveOnlySelfWithCompletion
:
completion
];
}
...
...
GMPhobos/Classes/PhobosSendManager.h
View file @
ffca9286
...
...
@@ -12,9 +12,11 @@ NS_ASSUME_NONNULL_BEGIN
@interface
PhobosSendManager
:
NSObject
/**
* 发送数据
*/
+
(
void
)
sendDataWithEntities
:(
NSArray
<
PhobosSendDataEntity
*>
*
)
needSendData
completion
:(
nullable
void
(
^
)(
NSArray
<
PhobosSendDataEntity
*>
*
finishEntities
,
NSInteger
code
))
completion
;
@end
NS_ASSUME_NONNULL_END
GMPhobos/Classes/PhobosSendManager.m
View file @
ffca9286
...
...
@@ -23,6 +23,7 @@
+
(
void
)
initialize
{
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
// 处理非灰情况下未发送完成数据
[
self
disposeOldData
];
});
}
...
...
@@ -35,6 +36,7 @@
[
total
addObjectsFromArray
:
normalDataArray
];
[
total
addObjectsFromArray
:
immiDataArray
];
if
(
total
.
count
>
0
)
{
/** 获取非灰度下所有普通埋点,进行发送 */
[
self
sendDataArray
:
total
currentAPI
:
Phobos
.
sharedClient
.
serverAPI
success
:^
(
NSInteger
code
)
{
if
(
code
==
200
)
{
[
GMCache
removeObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
...
...
@@ -45,6 +47,7 @@
NSString
*
exposureAPI
=
GMExactExposureApi
;
NSArray
*
exposureArray
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:[
PhobosUtil
MD5String
:
exposureAPI
]];
if
(
exposureArray
.
count
>
0
)
{
/** 获取非灰度下发送失败的埋点,进行发送 */
[
self
sendDataArray
:
exposureArray
currentAPI
:
exposureAPI
success
:^
(
NSInteger
code
)
{
if
(
code
=
200
)
{
[
GMCache
removeObjectAtDocumentPathWithkey
:[
PhobosUtil
MD5String
:
exposureAPI
]];
...
...
@@ -57,9 +60,11 @@
if
(
sendDataEntities
.
count
==
0
)
{
return
;
}
else
if
(
sendDataEntities
.
count
>
PhobosMaxSendCount
)
{
/** 如果数据超过 PhobosMaxSendCount 数据规模,进行拆分,分批发送,默认100条 */
NSMutableArray
*
temp
=
[
NSMutableArray
arrayWithCapacity
:
PhobosMaxSendCount
];
[
sendDataEntities
enumerateObjectsUsingBlock
:
^
(
PhobosSendDataEntity
*
_Nonnull
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
if
(
temp
.
count
>=
PhobosMaxSendCount
)
{
// 会调用当前方法,但数据规模不会满足 > PhobosMaxSendCount,不会让数据走到下面的发送,拆分完成 会执行return
[
self
sendDataWithEntities
:
temp
completion
:
completion
];
[
temp
removeAllObjects
];
}
...
...
@@ -68,14 +73,15 @@
return
;
}
NSMutableDictionary
*
sendDataMap
=
[
NSMutableDictionary
new
];
// 将相同api的数据合并
[
sendDataEntities
enumerateObjectsUsingBlock
:
^
(
PhobosSendDataEntity
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
NSMutableArray
*
sendData
=
sendDataMap
[
obj
.
api
]
?:
[
NSMutableArray
new
];
[
sendData
addObject
:
obj
];
[
sendDataMap
setValue
:
sendData
forKey
:
obj
.
api
];
}];
// 将实体转为待发送数据,取出PhobosSendDataEntity中的data,并发送
[
sendDataMap
enumerateKeysAndObjectsUsingBlock
:
^
(
NSString
*
api
,
NSArray
<
PhobosSendDataEntity
*>
*
entities
,
BOOL
*
_Nonnull
stop
)
{
// TODO: 如果数据量过大,
NSMutableArray
*
sendDatas
=
[
NSMutableArray
new
];
[
entities
enumerateObjectsUsingBlock
:
^
(
PhobosSendDataEntity
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
[
sendDatas
addObject
:[
obj
.
data
mj_JSONObject
]];
...
...
GMPhobos/Classes/UIResponder+PhobosPV.m
View file @
ffca9286
...
...
@@ -47,6 +47,7 @@
// 适用于链路中页面浏览事件的统计 添加 refererLink 参数
-
(
void
)
initRefererLink
{
// 添加 self.referrerLink.count == 0 ,处理referrerLink有值,就不需要初始化,为后期push、UniversalLinks修改referrerLink进行扩展,否则会重新被赋值
if
(
self
.
referrerLink
.
count
==
0
&&
[
self
isKindOfClass
:[
UIViewController
class
]])
{
// 分present与navigation两种情况
UIViewController
*
me
=
(
UIViewController
*
)
self
;
...
...
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