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
cc7f7ede
Commit
cc7f7ede
authored
Apr 11, 2020
by
井庆林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code review
parent
6b1ba75f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
17 deletions
+17
-17
GMViewController.m
Example/GMPhobos/GMViewController.m
+3
-3
PhobosDataManager.h
GMPhobos/Classes/PhobosDataManager.h
+3
-3
PhobosDataManager.m
GMPhobos/Classes/PhobosDataManager.m
+11
-11
No files found.
Example/GMPhobos/GMViewController.m
View file @
cc7f7ede
...
...
@@ -68,9 +68,9 @@ NSString *const MockCityId = @"beijing";
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
[
Phobos
track
:[
NSString
stringWithFormat
:
@"test-%d"
,
i
]
attributes
:
dict
sendNow
:
YES
];
//
dispatch_async(dispatch_get_global_queue(0, 0), ^{
//
[Phobos track:[NSString stringWithFormat:@"page_view-%d", i] attributes:dict];// sendNow:(i % 2) == 0];
//
});
dispatch_async
(
dispatch_get_global_queue
(
0
,
0
),
^
{
[
Phobos
track
:[
NSString
stringWithFormat
:
@"page_view-%d"
,
i
]
attributes
:
dict
];
// sendNow:(i % 2) == 0];
});
}
}
...
...
GMPhobos/Classes/PhobosDataManager.h
View file @
cc7f7ede
...
...
@@ -26,17 +26,17 @@ typedef NS_ENUM(NSInteger, PhobosDataSendStatus) {
/**
* 通过 searchFilter 获取数据
*/
+
(
void
)
fetchDataEntitiesWithPredicate
:(
NSPredicate
*
)
searchFilter
;
+
(
void
)
fetchDataEntitiesWithPredicate
:(
NSPredicate
*
)
searchFilter
entitiesBlock
:(
void
(
^
)(
NSArray
<
PhobosSendDataEntity
*>
*
entities
))
entitiesBlock
;
/**
* 获取待发送和发送失败的数据数量
*/
+
(
void
)
fetchCountOfToBeSendEntities
;
+
(
void
)
fetchCountOfToBeSendEntities
WithCountBlock
:(
nonnull
void
(
^
)(
NSUInteger
count
))
countBlock
;
/**
* 通过 searchFilter 获取数据数量
*/
+
(
void
)
fetchCountOfEntitiesWithPredicate
:(
NSPredicate
*
)
searchFilter
;
+
(
void
)
fetchCountOfEntitiesWithPredicate
:(
NSPredicate
*
)
searchFilter
countBlock
:(
nonnull
void
(
^
)(
NSUInteger
count
))
countBlock
;
/**
* 插入埋点数据
...
...
GMPhobos/Classes/PhobosDataManager.m
View file @
cc7f7ede
...
...
@@ -20,7 +20,7 @@ static dispatch_queue_t PhobosDataSaveQueue;
+
(
void
)
initialize
{
static
dispatch_once_t
onceToken
;
dispatch_once
(
&
onceToken
,
^
{
PhobosDataSaveQueue
=
dispatch_queue_create
(
"dispatch_
queue_phobos"
,
DISPATCH_QUEUE_SERIAL
);
PhobosDataSaveQueue
=
dispatch_queue_create
(
"dispatch_
rw_queue_phobos"
,
DISPATCH_QUEUE_CONCURRENT
);
// 创建 NSManagedObjectContext,供埋点库访问CoreData库使用
PhobosDefaultContext
=
[[
NSManagedObjectContext
alloc
]
initWithConcurrencyType
:
NSPrivateQueueConcurrencyType
];
...
...
@@ -49,10 +49,10 @@ static dispatch_queue_t PhobosDataSaveQueue;
/** 将发送成功的数据删除 */
NSPredicate
*
finishPredicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d"
,
PhobosDataSendStatusFinish
];
[
PhobosSendDataEntity
MR_deleteAllMatchingPredicate
:
finishPredicate
];
//
[self fetchDataEntitiesWithPredicate:finishPredicate entitiesBlock:^(NSArray<PhobosSendDataEntity *> * finishEntities) {
//
[self deleteDataEntities:finishEntities];
//
}];
//
[PhobosSendDataEntity MR_deleteAllMatchingPredicate:finishPredicate];
[
self
fetchDataEntitiesWithPredicate
:
finishPredicate
entitiesBlock
:
^
(
NSArray
<
PhobosSendDataEntity
*>
*
finishEntities
)
{
[
self
deleteDataEntities
:
finishEntities
];
}];
});
}
...
...
@@ -62,7 +62,7 @@ static dispatch_queue_t PhobosDataSaveQueue;
}
+
(
void
)
fetchDataEntitiesWithPredicate
:
(
NSPredicate
*
)
searchFilter
entitiesBlock
:
(
nonnull
void
(
^
)(
NSArray
<
PhobosSendDataEntity
*>
*
))
entitiesBlock
{
dispatch_
a
sync
(
PhobosDataSaveQueue
,
^
{
dispatch_sync
(
PhobosDataSaveQueue
,
^
{
NSArray
<
PhobosSendDataEntity
*>
*
entities
=
[
PhobosSendDataEntity
MR_findAllWithPredicate
:
searchFilter
inContext
:
PhobosDefaultContext
];
if
(
entitiesBlock
)
{
entitiesBlock
(
entities
);
...
...
@@ -76,7 +76,7 @@ static dispatch_queue_t PhobosDataSaveQueue;
}
+
(
void
)
fetchCountOfEntitiesWithPredicate
:
(
NSPredicate
*
)
searchFilter
countBlock
:
(
nonnull
void
(
^
)(
NSUInteger
))
countBlock
{
dispatch_
a
sync
(
PhobosDataSaveQueue
,
^
{
dispatch_sync
(
PhobosDataSaveQueue
,
^
{
NSUInteger
count
=
[[
PhobosSendDataEntity
MR_numberOfEntitiesWithPredicate
:
searchFilter
inContext
:
PhobosDefaultContext
]
integerValue
];
if
(
countBlock
)
{
countBlock
(
count
);
...
...
@@ -92,7 +92,7 @@ static dispatch_queue_t PhobosDataSaveQueue;
if
(
!
sendAPI
||
[
sendAPI
isEqualToString
:
@""
]
||
!
data
)
{
return
;
}
dispatch_async
(
PhobosDataSaveQueue
,
^
{
dispatch_
barrier_
async
(
PhobosDataSaveQueue
,
^
{
PhobosSendDataEntity
*
entity
=
[
PhobosSendDataEntity
MR_createEntityInContext
:
PhobosDefaultContext
];
entity
.
data
=
[
data
mj_JSONData
];
entity
.
api
=
sendAPI
;
...
...
@@ -108,7 +108,7 @@ static dispatch_queue_t PhobosDataSaveQueue;
+
(
void
)
updateDataEntities
:
(
NSArray
<
PhobosSendDataEntity
*>
*
)
entities
sendStatus
:
(
PhobosDataSendStatus
)
sendStatus
completion
:
(
MRSaveCompletionHandler
)
completion
{
if
(
entities
.
count
>
0
)
{
dispatch_async
(
PhobosDataSaveQueue
,
^
{
dispatch_
barrier_
async
(
PhobosDataSaveQueue
,
^
{
NSInteger
count
=
entities
.
count
;
[
entities
enumerateObjectsUsingBlock
:
^
(
PhobosSendDataEntity
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
obj
.
status
=
sendStatus
;
...
...
@@ -122,7 +122,7 @@ static dispatch_queue_t PhobosDataSaveQueue;
+
(
void
)
deleteDataEntities
:
(
NSArray
<
PhobosSendDataEntity
*>
*
)
entities
{
if
(
entities
.
count
>
0
)
{
dispatch_async
(
PhobosDataSaveQueue
,
^
{
dispatch_
barrier_
async
(
PhobosDataSaveQueue
,
^
{
NSInteger
count
=
entities
.
count
;
[
entities
enumerateObjectsUsingBlock
:
^
(
PhobosSendDataEntity
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
[
obj
MR_deleteEntityInContext
:
PhobosDefaultContext
];
...
...
@@ -135,7 +135,7 @@ static dispatch_queue_t PhobosDataSaveQueue;
}
+
(
void
)
deleteAllEntities
{
dispatch_async
(
PhobosDataSaveQueue
,
^
{
dispatch_
barrier_
async
(
PhobosDataSaveQueue
,
^
{
[
PhobosSendDataEntity
MR_truncateAllInContext
:
PhobosDefaultContext
];
[
self
saveWithCompletion
:
nil
];
});
...
...
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