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
c606fc11
Commit
c606fc11
authored
Mar 06, 2020
by
井庆林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
..
parent
0323d362
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
77 additions
and
127 deletions
+77
-127
GMViewController.m
Example/GMPhobos/GMViewController.m
+15
-8
Podfile
Example/Podfile
+1
-0
Podfile.lock
Example/Podfile.lock
+1
-1
GMPhotoTest.m
Example/Tests/GMPhotoTest.m
+0
-0
NewPhobos.h
GMPhobos/Classes/NewPhobos.h
+5
-15
NewPhobos.m
GMPhobos/Classes/NewPhobos.m
+12
-39
Phobos.h
GMPhobos/Classes/Phobos.h
+6
-17
Phobos.m
GMPhobos/Classes/Phobos.m
+9
-36
PhobosDataManager.h
GMPhobos/Classes/PhobosDataManager.h
+8
-2
PhobosDataManager.m
GMPhobos/Classes/PhobosDataManager.m
+17
-9
PhobosSendManager.m
GMPhobos/Classes/PhobosSendManager.m
+3
-0
No files found.
Example/GMPhobos/GMViewController.m
View file @
c606fc11
...
...
@@ -58,19 +58,26 @@ NSString *const MockCityId = @"beijing";
[
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
];
//
[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
sendNow
:
YES
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
//
array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
[
Phobos
track
:
@"test"
attributes
:
dict
];
array
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosCacheKey
];
[
Phobos
track
:
@"test"
attributes
:
dict
sendNow
:
YES
];
[
Phobos
track
:
@"test2"
attributes
:
dict
sendNow
:
YES
];
[
Phobos
track
:
@"test3"
attributes
:
dict
sendNow
:
YES
];
[
Phobos
track
:
@"test4"
attributes
:
dict
sendNow
:
YES
];
[
Phobos
track
:
@"test3"
attributes
:
dict
sendNow
:
YES
];
[
Phobos
track
:
@"test4"
attributes
:
dict
sendNow
:
YES
];
[
Phobos
track
:
@"test3"
attributes
:
dict
sendNow
:
YES
];
[
Phobos
track
:
@"test4"
attributes
:
dict
sendNow
:
YES
];
// array = [GMCache fetchObjectAtDocumentPathWithkey:PhobosCacheKey];
}
...
...
Example/Podfile
View file @
c606fc11
...
...
@@ -8,6 +8,7 @@ inhibit_all_warnings!
target
'GMPhobos_Example'
do
pod
'GMPhobos'
,
:path
=>
'../'
# pod 'GMPhobos', :git => 'git@git.wanmeizhensuo.com:gengmeiios/GMPhobos.git', :branch => 'jql/coreData'
target
'GMPhobos_Tests'
do
inherit!
:search_paths
end
...
...
Example/Podfile.lock
View file @
c606fc11
...
...
@@ -33,6 +33,6 @@ SPEC CHECKSUMS:
MJExtension: 635f2c663dcb1bf76fa4b715b2570a5710aec545
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
PODFILE CHECKSUM:
4db0de045b595396507d6bad04e4823b02c3061d
PODFILE CHECKSUM:
abbb682362e2d6dbd228843955b17f6796b958b0
COCOAPODS: 1.8.4
Example/Tests/GMPhotoTest.m
View file @
c606fc11
This diff is collapsed.
Click to expand it.
GMPhobos/Classes/NewPhobos.h
View file @
c606fc11
...
...
@@ -166,23 +166,13 @@ NS_ASSUME_NONNULL_BEGIN
@interface
NewPhobos
(
UtilTest
)
/** 获取所有非立即发送埋点数量 */
+
(
NSInteger
)
normalPhobos
Count
;
+
(
NSInteger
)
fetchToBeSendPhobosData
Count
;
/** 获取
所有非立即
发送埋点数据 */
+
(
NSArray
*
)
normal
PhobosData
;
/** 获取
待
发送埋点数据 */
+
(
NSArray
*
)
fetchToBeSend
PhobosData
;
/** 获取所有立即发送埋点数量 */
+
(
NSUInteger
)
immediatelyPhobosCount
;
/** 获取所有立即发送埋点数据 */
+
(
NSArray
*
)
immediatelyPhobosData
;
/** 清除非立即发送埋点数据缓存 */
+
(
void
)
removeAllNormalPhobosData
;
/** 清除立即发送埋点数据缓存 */
+
(
void
)
removeAllImmediatelyPhobosData
;
/** 清除待发送埋点数据缓存 */
+
(
void
)
removeAllPhobosData
;
@end
...
...
GMPhobos/Classes/NewPhobos.m
View file @
c606fc11
...
...
@@ -386,15 +386,8 @@ static NSString *sdkVersion = @"1.4.0";
NSDictionary
*
dataDict
=
[
_sharedClient
prepareDictionaryForEvent
:
eventName
attributes
:
attributes
];
@try
{
NSData
*
JSON
=
[
PhobosUtil
encodeJSON
:
dataDict
];
[
PhobosDataManager
insertData
:
dataDict
sendAPI
:
currentAPI
immediately
:
sendNow
completion
:^
(
BOOL
contextDidSave
,
NSError
*
_Nullable
error
)
{
if
(
sendNow
)
{
[
self
disposeSendDataWithImmediately
:
YES
];
}
else
{
NSArray
<
SendDataEntity
*>
*
fetchArray
=
[
PhobosDataManager
fetchDataEntitiesWithImmediately
:
NO
];
if
(
fetchArray
.
count
>
50
)
{
[
self
disposeSendDataWithImmediately
:
NO
];
}
}
[
PhobosDataManager
insertData
:
dataDict
sendAPI
:
currentAPI
completion
:^
(
BOOL
contextDidSave
,
NSError
*
_Nullable
error
)
{
[
self
disposeSendDataWithImmediately
:
sendNow
];
}];
}
@catch
(
NSException
*
exception
)
{
NSAssert
(
NO
,
@"哎呀呀,VALUE不能为NSObject "
);
...
...
@@ -405,8 +398,8 @@ static NSString *sdkVersion = @"1.4.0";
* 处理发送数据
*/
+
(
void
)
disposeSendDataWithImmediately
:
(
BOOL
)
immediately
{
NSArray
<
SendDataEntity
*>
*
entities
=
[
PhobosDataManager
fetch
DataEntitiesWithImmediately
:
immediately
];
if
(
entities
.
count
>
0
)
{
NSArray
<
SendDataEntity
*>
*
entities
=
[
PhobosDataManager
fetch
ToBeSendDataEntities
];
if
(
immediately
||
entities
.
count
>
5
0
)
{
[
PhobosDataManager
updateDataEntities
:
entities
sendStatus
:
PhobosDataSendStatusSending
completion
:
nil
];
[
PhobosSendManager
sendDataWithEntities
:
entities
completion
:
^
(
NSArray
<
SendDataEntity
*>
*
_Nonnull
finishEntities
,
NSInteger
code
)
{
if
(
code
==
200
)
{
...
...
@@ -425,37 +418,17 @@ static NSString *sdkVersion = @"1.4.0";
@implementation
NewPhobos
(
UtilTest
)
/** 获取所有非立即发送埋点数量 */
+
(
NSInteger
)
normalPhobosCount
{
NSPredicate
*
predicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d"
,
PhobosDataSendStatusNormal
];
return
[
PhobosDataManager
fetchCountOfEntitiesWithPredicate
:
predicate
];
}
/** 获取所有非立即发送埋点数据 */
+
(
NSArray
*
)
normalPhobosData
{
return
[
PhobosDataManager
fetchDataEntitiesWithImmediately
:
NO
];
+
(
NSInteger
)
fetchToBeSendPhobosDataCount
{
return
[
PhobosDataManager
fetchCountOfToBeSendEntities
];
}
/** 获取所有立即发送埋点数量 */
+
(
NSUInteger
)
immediatelyPhobosCount
{
NSPredicate
*
predicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d or status = %d"
,
PhobosDataSendStatusToBeSend
,
PhobosDataSendStatusError
];
return
[
PhobosDataManager
fetchCountOfEntitiesWithPredicate
:
predicate
];
}
/** 获取所有立即发送埋点数据 */
+
(
NSArray
*
)
immediatelyPhobosData
{
return
[
PhobosDataManager
fetchDataEntitiesWithImmediately
:
YES
];
}
/** 清除非立即发送埋点数据缓存 */
+
(
void
)
removeAllNormalPhobosData
{
NSArray
<
SendDataEntity
*>
*
fetchArray
=
[
PhobosDataManager
fetchDataEntitiesWithImmediately
:
NO
];
[
PhobosDataManager
deleteDataEntities
:
fetchArray
];
/** 获取待发送埋点数据 */
+
(
NSArray
*
)
fetchToBeSendPhobosData
{
return
[
PhobosDataManager
fetchToBeSendDataEntities
];
}
/** 清除立即发送埋点数据缓存 */
+
(
void
)
removeAllImmediatelyPhobosData
{
NSArray
<
SendDataEntity
*>
*
fetchArray
=
[
PhobosDataManager
fetchDataEntitiesWithImmediately
:
YES
];
[
PhobosDataManager
deleteDataEntities
:
fetchArray
];
/** 清除待发送埋点数据缓存 */
+
(
void
)
removeAllPhobosData
{
[
PhobosDataManager
deleteAllEntities
];
}
@end
GMPhobos/Classes/Phobos.h
View file @
c606fc11
...
...
@@ -160,25 +160,14 @@ NS_ASSUME_NONNULL_BEGIN
@interface
Phobos
(
UtilTest
)
/** 获取
所有非立即
发送埋点数量 */
+
(
NSInteger
)
normalPhobos
Count
;
/** 获取
待
发送埋点数量 */
+
(
NSInteger
)
fetchToBeSendPhobosData
Count
;
/** 获取所有非立即发送埋点数据 */
+
(
NSArray
*
)
normalPhobosData
;
/** 获取所有立即发送埋点数量 */
+
(
NSUInteger
)
immediatelyPhobosCount
;
/** 获取所有立即发送埋点数据 */
+
(
NSArray
*
)
immediatelyPhobosData
;
/** 清除非立即发送埋点数据缓存 */
+
(
void
)
removeAllNormalPhobosData
;
/** 清除立即发送埋点数据缓存 */
+
(
void
)
removeAllImmediatelyPhobosData
;
/** 获取待发送埋点数据 */
+
(
NSArray
*
)
fetchToBeSendPhobosData
;
/** 清除待发送埋点数据缓存 */
+
(
void
)
removeAllPhobosData
;
@end
NS_ASSUME_NONNULL_END
GMPhobos/Classes/Phobos.m
View file @
c606fc11
...
...
@@ -212,47 +212,20 @@ static BOOL isGray = NO;
@implementation
NewPhobos
(
UtilTest
)
/** 获取
所有非立即
发送埋点数量 */
+
(
NS
Integer
)
normalPhobos
Count
{
return
isGray
?
[
NewPhobos
normalPhobos
Count
]
:
0
;
/** 获取
待
发送埋点数量 */
+
(
NS
UInteger
)
fetchToBeSendPhobosData
Count
{
return
isGray
?
[
NewPhobos
fetchToBeSendPhobosData
Count
]
:
0
;
}
/** 获取
所有非立即
发送埋点数据 */
+
(
NSArray
*
)
normal
PhobosData
{
return
isGray
?
[
NewPhobos
normalPhobosData
]
:
nil
;
/** 获取
待
发送埋点数据 */
+
(
NSArray
*
)
fetchToBeSend
PhobosData
{
return
isGray
?
[
NewPhobos
fetchToBeSendPhobosData
]
:
@[]
;
}
/** 获取所有立即发送埋点数量 */
+
(
NSUInteger
)
immediatelyPhobosCount
{
return
isGray
?
[
NewPhobos
immediatelyPhobosCount
]
:
0
;
}
/** 获取所有立即发送埋点数据 */
+
(
NSDictionary
*
)
immediatelyPhobosData
{
return
isGray
?
[
NewPhobos
immediatelyPhobosData
]
:
nil
;
}
/** 获取url的立即发送埋点数据 */
+
(
NSArray
*
)
immediatelyPhobosDataForURL
:
(
NSString
*
)
url
{
return
isGray
?
[
NewPhobos
immediatelyPhobosDataForURL
:
url
]
:
nil
;
}
+
(
NSUInteger
)
immediatelyPhobosCountForURL
:
(
NSString
*
)
url
{
return
isGray
?
[
NewPhobos
immediatelyPhobosCountForURL
:
url
]
:
0
;
}
/** 清除非立即发送埋点数据缓存 */
+
(
void
)
removeAllNormalPhobosData
{
if
(
isGray
)
{
[
NewPhobos
removeAllNormalPhobosData
];
}
}
/** 清除立即发送埋点数据缓存 */
+
(
void
)
removeAllImmediatelyPhobosData
{
/** 清除待发送埋点数据缓存 */
+
(
void
)
removeAllPhobosData
{
if
(
isGray
)
{
[
NewPhobos
removeAll
Normal
PhobosData
];
[
NewPhobos
removeAllPhobosData
];
}
}
...
...
GMPhobos/Classes/PhobosDataManager.h
View file @
c606fc11
...
...
@@ -21,12 +21,18 @@ typedef NS_ENUM(NSInteger, PhobosDataSendStatus) {
@interface
PhobosDataManager
:
NSObject
+
(
NSArray
<
SendDataEntity
*>
*
)
fetchDataEntitiesWithImmediately
:(
BOOL
)
immediately
;
/** 获取待发送数据,包含待发送数据和发送失败数据 */
+
(
NSArray
<
SendDataEntity
*>
*
)
fetchToBeSendDataEntities
;
+
(
NSArray
<
SendDataEntity
*>
*
)
fetchDataEntitiesWithPredicate
:(
NSPredicate
*
)
searchFilter
;
+
(
NSUInteger
)
fetchCountOfToBeSendEntities
;
+
(
NSUInteger
)
fetchCountOfEntitiesWithPredicate
:(
NSPredicate
*
)
searchFilter
;
+
(
void
)
insertData
:(
NSDictionary
*
)
data
sendAPI
:(
NSString
*
)
sendAPI
immediately
:(
BOOL
)
immediately
completion
:(
MRSaveCompletionHandler
)
completion
;
+
(
void
)
insertData
:(
NSDictionary
*
)
data
sendAPI
:(
NSString
*
)
sendAPI
completion
:(
MRSaveCompletionHandler
)
completion
;
+
(
void
)
updateDataEntities
:(
NSArray
<
SendDataEntity
*>
*
)
entities
sendStatus
:(
PhobosDataSendStatus
)
sendStatus
completion
:(
MRSaveCompletionHandler
)
completion
;
+
(
void
)
deleteDataEntities
:(
NSArray
<
SendDataEntity
*>
*
)
entities
;
+
(
void
)
deleteAllEntities
;
@end
...
...
GMPhobos/Classes/PhobosDataManager.m
View file @
c606fc11
...
...
@@ -25,16 +25,14 @@ static NSManagedObjectContext *Phobos_defaultContext;
NSManagedObjectModel
*
model
=
[[
NSManagedObjectModel
alloc
]
initWithContentsOfURL
:
modelURL
];
[
NSManagedObjectModel
MR_setDefaultManagedObjectModel
:
model
];
[
MagicalRecord
setupAutoMigratingCoreDataStack
];
NSPredicate
*
predicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d"
,
PhobosDataSendStatusSending
];
NSArray
<
SendDataEntity
*>
*
entities
=
[
self
fetchDataEntitiesWithPredicate
:
predicate
];
[
self
updateDataEntities
:
entities
sendStatus
:
PhobosDataSendStatusError
completion
:
nil
];
});
}
+
(
NSArray
<
SendDataEntity
*>
*
)
fetchDataEntitiesWithImmediately
:
(
BOOL
)
immediately
{
NSPredicate
*
predicate
;
if
(
immediately
)
{
predicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d or status = %d"
,
PhobosDataSendStatusToBeSend
,
PhobosDataSendStatusError
];
}
else
{
predicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d"
,
PhobosDataSendStatusNormal
];
}
+
(
NSArray
<
SendDataEntity
*>
*
)
fetchToBeSendDataEntities
{
NSPredicate
*
predicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d or status = %d"
,
PhobosDataSendStatusToBeSend
,
PhobosDataSendStatusError
];
return
[
self
fetchDataEntitiesWithPredicate
:
predicate
];
}
...
...
@@ -42,18 +40,23 @@ static NSManagedObjectContext *Phobos_defaultContext;
return
[
SendDataEntity
MR_findAllWithPredicate
:
searchFilter
inContext
:[
NSManagedObjectContext
MR_defaultContext
]];
}
+
(
NSUInteger
)
fetchCountOfToBeSendEntities
{
NSPredicate
*
predicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d or status = %d"
,
PhobosDataSendStatusToBeSend
,
PhobosDataSendStatusError
];
return
[
self
fetchCountOfEntitiesWithPredicate
:
predicate
];
}
+
(
NSUInteger
)
fetchCountOfEntitiesWithPredicate
:
(
NSPredicate
*
)
searchFilter
{
return
[
SendDataEntity
MR_numberOfEntitiesWithPredicate
:
searchFilter
inContext
:[
NSManagedObjectContext
MR_defaultContext
]];
}
+
(
void
)
insertData
:
(
NSDictionary
*
)
data
sendAPI
:
(
NSString
*
)
sendAPI
immediately
:
(
BOOL
)
immediately
completion
:
(
MRSaveCompletionHandler
)
completion
{
+
(
void
)
insertData
:
(
NSDictionary
*
)
data
sendAPI
:
(
NSString
*
)
sendAPI
completion
:
(
MRSaveCompletionHandler
)
completion
{
if
(
!
sendAPI
||
[
sendAPI
isEqualToString
:
@""
]
||
!
data
)
{
return
;
}
SendDataEntity
*
entity
=
[
SendDataEntity
MR_createEntity
];
entity
.
data
=
[
data
mj_JSONData
];
entity
.
api
=
sendAPI
;
entity
.
status
=
immediately
?
PhobosDataSendStatusToBeSend
:
PhobosDataSendStatusNormal
;
entity
.
status
=
PhobosDataSendStatusToBeSend
;
entity
.
id
=
[
PhobosUtil
currentMMTime
];
[[
NSManagedObjectContext
MR_defaultContext
]
MR_saveWithOptions
:
MRSaveSynchronously
completion
:
completion
];
}
...
...
@@ -76,4 +79,9 @@ static NSManagedObjectContext *Phobos_defaultContext;
}
}
+
(
void
)
deleteAllEntities
{
[
SendDataEntity
MR_truncateAll
];
[[
NSManagedObjectContext
MR_defaultContext
]
MR_saveOnlySelfAndWait
];
}
@end
GMPhobos/Classes/PhobosSendManager.m
View file @
c606fc11
...
...
@@ -26,6 +26,7 @@
});
}
// TODO: 全量以后,一定时间需要清除下面逻辑
+
(
void
)
disposeOldData
{
NSMutableArray
*
total
=
[
NSMutableArray
new
];
NSArray
*
normalDataArray
=
[
GMCache
fetchObjectAtDocumentPathWithkey
:
PhobosTempCacheKey
];
...
...
@@ -63,10 +64,12 @@
}];
[
sendDataMap
enumerateKeysAndObjectsUsingBlock
:
^
(
NSString
*
api
,
NSArray
<
SendDataEntity
*>
*
entities
,
BOOL
*
_Nonnull
stop
)
{
// TODO: 如果数据量过大,
NSMutableArray
*
sendDatas
=
[
NSMutableArray
new
];
[
entities
enumerateObjectsUsingBlock
:
^
(
SendDataEntity
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
[
sendDatas
addObject
:[
obj
.
data
mj_JSONObject
]];
}];
if
(
sendDatas
.
count
>
0
)
{
[
self
sendDataArray
:
sendDatas
currentAPI
:
api
success
:^
(
NSInteger
code
)
{
if
(
completion
)
{
...
...
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