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