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
049fe1cc
Commit
049fe1cc
authored
Mar 25, 2020
by
井庆林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
parent
783bf483
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
35 deletions
+27
-35
GMPhobos-Example.xcscheme
...codeproj/xcshareddata/xcschemes/GMPhobos-Example.xcscheme
+9
-13
GMPhotoTest.m
Example/Tests/GMPhotoTest.m
+3
-5
NewPhobos.m
GMPhobos/Classes/NewPhobos.m
+6
-8
PhobosDataManager.h
GMPhobos/Classes/PhobosDataManager.h
+2
-2
PhobosDataManager.m
GMPhobos/Classes/PhobosDataManager.m
+7
-7
No files found.
Example/GMPhobos.xcodeproj/xcshareddata/xcschemes/GMPhobos-Example.xcscheme
View file @
049fe1cc
...
...
@@ -27,6 +27,15 @@
selectedDebuggerIdentifier =
"Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier =
"Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv =
"YES"
>
<MacroExpansion>
<BuildableReference
BuildableIdentifier =
"primary"
BlueprintIdentifier =
"6003F589195388D20070C39A"
BuildableName =
"GMPhobos_Example.app"
BlueprintName =
"GMPhobos_Example"
ReferencedContainer =
"container:GMPhobos.xcodeproj"
>
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped =
"NO"
>
...
...
@@ -54,17 +63,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier =
"primary"
BlueprintIdentifier =
"6003F589195388D20070C39A"
BuildableName =
"GMPhobos_Example.app"
BlueprintName =
"GMPhobos_Example"
ReferencedContainer =
"container:GMPhobos.xcodeproj"
>
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration =
"Debug"
...
...
@@ -86,8 +84,6 @@
ReferencedContainer =
"container:GMPhobos.xcodeproj"
>
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration =
"Release"
...
...
Example/Tests/GMPhotoTest.m
View file @
049fe1cc
...
...
@@ -163,7 +163,7 @@ NSString *const MockCityId = @"beijing";
XCTAssertTrue
([
Phobos
fetchToBeSendPhobosDataCount
]
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
XCTAssertTrue
([
Phobos
fetchToBeSendPhobosDataCount
]
==
2
,
@"array shouldn't be empty"
);
XCTAssertTrue
([
Phobos
fetchToBeSendPhobosDataCount
]
==
1
,
@"array shouldn't be empty"
);
}
/**
...
...
@@ -222,12 +222,10 @@ NSString *const MockCityId = @"beijing";
for
(
int
i
=
0
;
i
<
50
;
i
++
)
{
[
Phobos
track
:
MockEventId
attributes
:
attr
];
}
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
fetchToBeSendPhobosDataCount
]
==
1
,
@"array shouldn't be empty"
);
XCTAssertTrue
([
Phobos
fetchToBeSendPhobosDataCount
]
==
0
,
@"array shouldn't be empty"
);
[
Phobos
track
:
MockEventId
attributes
:
attr
];
[
NSThread
sleepForTimeInterval
:
0
.
2
];
XCTAssertTrue
([
Phobos
fetchToBeSendPhobosDataCount
]
==
2
,
@"array shouldn't be empty"
);
XCTAssertTrue
([
Phobos
fetchToBeSendPhobosDataCount
]
==
1
,
@"array shouldn't be empty"
);
}
-
(
void
)
verfiyDict
:
(
NSDictionary
*
)
dict
{
...
...
GMPhobos/Classes/NewPhobos.m
View file @
049fe1cc
...
...
@@ -389,9 +389,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
completion
:^
(
BOOL
contextDidSave
,
NSError
*
_Nullable
error
)
{
[
self
disposeSendDataWithImmediately
:
sendNow
];
}];
[
PhobosDataManager
insertData
:
dataDict
sendAPI
:
currentAPI
];
[
self
disposeSendDataWithImmediately
:
sendNow
];
}
@catch
(
NSException
*
exception
)
{
NSAssert
(
NO
,
@"哎呀呀,VALUE不能为NSObject "
);
}
...
...
@@ -403,14 +402,13 @@ static NSString *sdkVersion = @"1.4.0";
+
(
void
)
disposeSendDataWithImmediately
:
(
BOOL
)
immediately
{
NSArray
<
PhobosSendDataEntity
*>
*
entities
=
[
PhobosDataManager
fetchToBeSendDataEntities
];
if
(
immediately
||
entities
.
count
>
PhobosShardCount
)
{
[
PhobosDataManager
updateDataEntities
:
entities
sendStatus
:
PhobosDataSendStatusSending
completion
:
nil
];
[
PhobosDataManager
updateDataEntities
:
entities
sendStatus
:
PhobosDataSendStatusSending
];
[
PhobosSendManager
sendDataWithEntities
:
entities
completion
:
^
(
NSArray
<
PhobosSendDataEntity
*>
*
_Nonnull
finishEntities
,
NSInteger
code
)
{
if
(
code
==
200
)
{
[
PhobosDataManager
updateDataEntities
:
finishEntities
sendStatus
:
PhobosDataSendStatusFinish
completion
:^
(
BOOL
contextDidSave
,
NSError
*
_Nullable
error
)
{
[
PhobosDataManager
deleteDataEntities
:
finishEntities
];
}];
[
PhobosDataManager
deleteDataEntities
:
finishEntities
];
[
PhobosDataManager
updateDataEntities
:
finishEntities
sendStatus
:
PhobosDataSendStatusFinish
];
}
else
{
[
PhobosDataManager
updateDataEntities
:
finishEntities
sendStatus
:
PhobosDataSendStatusError
completion
:
nil
];
[
PhobosDataManager
updateDataEntities
:
finishEntities
sendStatus
:
PhobosDataSendStatusError
];
}
}];
}
...
...
GMPhobos/Classes/PhobosDataManager.h
View file @
049fe1cc
...
...
@@ -27,9 +27,9 @@ typedef NS_ENUM(NSInteger, PhobosDataSendStatus) {
+
(
NSUInteger
)
fetchCountOfToBeSendEntities
;
+
(
NSUInteger
)
fetchCountOfEntitiesWithPredicate
:(
NSPredicate
*
)
searchFilter
;
+
(
void
)
insertData
:(
NSDictionary
*
)
data
sendAPI
:(
NSString
*
)
sendAPI
completion
:(
MRSaveCompletionHandler
)
completion
;
+
(
void
)
insertData
:(
NSDictionary
*
)
data
sendAPI
:(
NSString
*
)
sendAPI
;
+
(
void
)
updateDataEntities
:(
NSArray
<
PhobosSendDataEntity
*>
*
)
entities
sendStatus
:(
PhobosDataSendStatus
)
sendStatus
completion
:(
MRSaveCompletionHandler
)
completion
;
+
(
void
)
updateDataEntities
:(
NSArray
<
PhobosSendDataEntity
*>
*
)
entities
sendStatus
:(
PhobosDataSendStatus
)
sendStatus
;
+
(
void
)
deleteDataEntities
:(
NSArray
<
PhobosSendDataEntity
*>
*
)
entities
;
+
(
void
)
deleteAllEntities
;
...
...
GMPhobos/Classes/PhobosDataManager.m
View file @
049fe1cc
...
...
@@ -37,7 +37,7 @@ static NSManagedObjectContext *Phobos_defaultContext;
NSPredicate
*
predicate
=
[
NSPredicate
predicateWithFormat
:
@"status = %d"
,
PhobosDataSendStatusSending
];
NSArray
<
PhobosSendDataEntity
*>
*
entities
=
[
self
fetchDataEntitiesWithPredicate
:
predicate
];
[
self
updateDataEntities
:
entities
sendStatus
:
PhobosDataSendStatusError
completion
:
nil
];
[
self
updateDataEntities
:
entities
sendStatus
:
PhobosDataSendStatusError
];
});
}
...
...
@@ -59,7 +59,7 @@ static NSManagedObjectContext *Phobos_defaultContext;
return
[[
PhobosSendDataEntity
MR_numberOfEntitiesWithPredicate
:
searchFilter
inContext
:
Phobos_defaultContext
]
integerValue
];
}
+
(
void
)
insertData
:
(
NSDictionary
*
)
data
sendAPI
:
(
NSString
*
)
sendAPI
completion
:
(
MRSaveCompletionHandler
)
completion
{
+
(
void
)
insertData
:
(
NSDictionary
*
)
data
sendAPI
:
(
NSString
*
)
sendAPI
{
if
(
!
sendAPI
||
[
sendAPI
isEqualToString
:
@""
]
||
!
data
)
{
return
;
}
...
...
@@ -68,15 +68,15 @@ static NSManagedObjectContext *Phobos_defaultContext;
entity
.
api
=
sendAPI
;
entity
.
status
=
PhobosDataSendStatusToBeSend
;
entity
.
id
=
mach_absolute_time
();
[
Phobos_defaultContext
MR_save
WithOptions
:
MRSaveSynchronously
completion
:
completion
];
[
Phobos_defaultContext
MR_save
OnlySelfWithCompletion
:
nil
];
}
+
(
void
)
updateDataEntities
:
(
NSArray
<
PhobosSendDataEntity
*>
*
)
entities
sendStatus
:
(
PhobosDataSendStatus
)
sendStatus
completion
:
(
MRSaveCompletionHandler
)
completion
{
+
(
void
)
updateDataEntities
:
(
NSArray
<
PhobosSendDataEntity
*>
*
)
entities
sendStatus
:
(
PhobosDataSendStatus
)
sendStatus
{
if
(
entities
.
count
>
0
)
{
[
entities
enumerateObjectsUsingBlock
:
^
(
PhobosSendDataEntity
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
obj
.
status
=
sendStatus
;
}];
[
Phobos_defaultContext
MR_save
WithOptions
:
MRSaveSynchronously
completion
:
completion
];
[
Phobos_defaultContext
MR_save
OnlySelfWithCompletion
:
nil
];
}
}
...
...
@@ -85,13 +85,13 @@ static NSManagedObjectContext *Phobos_defaultContext;
[
entities
enumerateObjectsUsingBlock
:
^
(
PhobosSendDataEntity
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
[
obj
MR_deleteEntityInContext
:
Phobos_defaultContext
];
}];
[
Phobos_defaultContext
MR_saveOnlySelf
AndWait
];
[
Phobos_defaultContext
MR_saveOnlySelf
WithCompletion
:
nil
];
}
}
+
(
void
)
deleteAllEntities
{
[
PhobosSendDataEntity
MR_truncateAllInContext
:
Phobos_defaultContext
];
[
Phobos_defaultContext
MR_saveOnlySelf
AndWait
];
[
Phobos_defaultContext
MR_saveOnlySelf
WithCompletion
:
nil
];
}
@end
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