Commit 049fe1cc authored by 井庆林's avatar 井庆林

修改

parent 783bf483
...@@ -27,6 +27,15 @@ ...@@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"> shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6003F589195388D20070C39A"
BuildableName = "GMPhobos_Example.app"
BlueprintName = "GMPhobos_Example"
ReferencedContainer = "container:GMPhobos.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables> <Testables>
<TestableReference <TestableReference
skipped = "NO"> skipped = "NO">
...@@ -54,17 +63,6 @@ ...@@ -54,17 +63,6 @@
</BuildableReference> </BuildableReference>
</TestableReference> </TestableReference>
</Testables> </Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6003F589195388D20070C39A"
BuildableName = "GMPhobos_Example.app"
BlueprintName = "GMPhobos_Example"
ReferencedContainer = "container:GMPhobos.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug" buildConfiguration = "Debug"
...@@ -86,8 +84,6 @@ ...@@ -86,8 +84,6 @@
ReferencedContainer = "container:GMPhobos.xcodeproj"> ReferencedContainer = "container:GMPhobos.xcodeproj">
</BuildableReference> </BuildableReference>
</BuildableProductRunnable> </BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
buildConfiguration = "Release" buildConfiguration = "Release"
......
...@@ -163,7 +163,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -163,7 +163,7 @@ NSString *const MockCityId = @"beijing";
XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 0, @"array shouldn't be empty"); XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 0, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:attr]; [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"; ...@@ -222,12 +222,10 @@ NSString *const MockCityId = @"beijing";
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
} }
[NSThread sleepForTimeInterval:0.2]; XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 0, @"array shouldn't be empty");
XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 1, @"array shouldn't be empty");
[Phobos track:MockEventId attributes:attr]; [Phobos track:MockEventId attributes:attr];
[NSThread sleepForTimeInterval:0.2]; XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 1, @"array shouldn't be empty");
XCTAssertTrue([Phobos fetchToBeSendPhobosDataCount] == 2, @"array shouldn't be empty");
} }
- (void)verfiyDict:(NSDictionary *)dict{ - (void)verfiyDict:(NSDictionary *)dict{
......
...@@ -389,9 +389,8 @@ static NSString *sdkVersion = @"1.4.0"; ...@@ -389,9 +389,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 completion:^(BOOL contextDidSave, NSError * _Nullable error) { [PhobosDataManager insertData:dataDict sendAPI:currentAPI];
[self disposeSendDataWithImmediately:sendNow]; [self disposeSendDataWithImmediately:sendNow];
}];
} @catch (NSException *exception) { } @catch (NSException *exception) {
NSAssert(NO, @"哎呀呀,VALUE不能为NSObject "); NSAssert(NO, @"哎呀呀,VALUE不能为NSObject ");
} }
...@@ -403,14 +402,13 @@ static NSString *sdkVersion = @"1.4.0"; ...@@ -403,14 +402,13 @@ static NSString *sdkVersion = @"1.4.0";
+ (void)disposeSendDataWithImmediately:(BOOL)immediately { + (void)disposeSendDataWithImmediately:(BOOL)immediately {
NSArray<PhobosSendDataEntity *> *entities = [PhobosDataManager fetchToBeSendDataEntities]; NSArray<PhobosSendDataEntity *> *entities = [PhobosDataManager fetchToBeSendDataEntities];
if (immediately || entities.count > PhobosShardCount) { 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) { [PhobosSendManager sendDataWithEntities:entities completion:^(NSArray<PhobosSendDataEntity *> * _Nonnull finishEntities, NSInteger code) {
if (code == 200) { 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 { } else {
[PhobosDataManager updateDataEntities:finishEntities sendStatus:PhobosDataSendStatusError completion:nil]; [PhobosDataManager updateDataEntities:finishEntities sendStatus:PhobosDataSendStatusError];
} }
}]; }];
} }
......
...@@ -27,9 +27,9 @@ typedef NS_ENUM(NSInteger, PhobosDataSendStatus) { ...@@ -27,9 +27,9 @@ typedef NS_ENUM(NSInteger, PhobosDataSendStatus) {
+ (NSUInteger)fetchCountOfToBeSendEntities; + (NSUInteger)fetchCountOfToBeSendEntities;
+ (NSUInteger)fetchCountOfEntitiesWithPredicate:(NSPredicate *)searchFilter; + (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)deleteDataEntities:(NSArray<PhobosSendDataEntity *> *)entities;
+ (void)deleteAllEntities; + (void)deleteAllEntities;
......
...@@ -37,7 +37,7 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -37,7 +37,7 @@ static NSManagedObjectContext *Phobos_defaultContext;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status = %d", PhobosDataSendStatusSending]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"status = %d", PhobosDataSendStatusSending];
NSArray<PhobosSendDataEntity *> *entities = [self fetchDataEntitiesWithPredicate:predicate]; 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; ...@@ -59,7 +59,7 @@ static NSManagedObjectContext *Phobos_defaultContext;
return [[PhobosSendDataEntity MR_numberOfEntitiesWithPredicate:searchFilter inContext:Phobos_defaultContext] integerValue]; 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) { if (!sendAPI || [sendAPI isEqualToString:@""] || !data) {
return; return;
} }
...@@ -68,15 +68,15 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -68,15 +68,15 @@ static NSManagedObjectContext *Phobos_defaultContext;
entity.api = sendAPI; entity.api = sendAPI;
entity.status = PhobosDataSendStatusToBeSend; entity.status = PhobosDataSendStatusToBeSend;
entity.id = mach_absolute_time(); entity.id = mach_absolute_time();
[Phobos_defaultContext MR_saveWithOptions:MRSaveSynchronously completion:completion]; [Phobos_defaultContext MR_saveOnlySelfWithCompletion:nil];
} }
+ (void)updateDataEntities:(NSArray<PhobosSendDataEntity *> *)entities sendStatus:(PhobosDataSendStatus)sendStatus completion:(MRSaveCompletionHandler)completion { + (void)updateDataEntities:(NSArray<PhobosSendDataEntity *> *)entities sendStatus:(PhobosDataSendStatus)sendStatus {
if (entities.count > 0) { if (entities.count > 0) {
[entities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) { [entities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) {
obj.status = sendStatus; obj.status = sendStatus;
}]; }];
[Phobos_defaultContext MR_saveWithOptions:MRSaveSynchronously completion:completion]; [Phobos_defaultContext MR_saveOnlySelfWithCompletion:nil];
} }
} }
...@@ -85,13 +85,13 @@ static NSManagedObjectContext *Phobos_defaultContext; ...@@ -85,13 +85,13 @@ static NSManagedObjectContext *Phobos_defaultContext;
[entities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) { [entities enumerateObjectsUsingBlock:^(PhobosSendDataEntity *obj, NSUInteger idx, BOOL * _Nonnull stop) {
[obj MR_deleteEntityInContext:Phobos_defaultContext]; [obj MR_deleteEntityInContext:Phobos_defaultContext];
}]; }];
[Phobos_defaultContext MR_saveOnlySelfAndWait]; [Phobos_defaultContext MR_saveOnlySelfWithCompletion:nil];
} }
} }
+ (void)deleteAllEntities { + (void)deleteAllEntities {
[PhobosSendDataEntity MR_truncateAllInContext:Phobos_defaultContext]; [PhobosSendDataEntity MR_truncateAllInContext:Phobos_defaultContext];
[Phobos_defaultContext MR_saveOnlySelfAndWait]; [Phobos_defaultContext MR_saveOnlySelfWithCompletion:nil];
} }
@end @end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment