Commit fd789797 authored by 汪洋's avatar 汪洋

优化captureNullExpection

parent 0e425556
...@@ -114,7 +114,7 @@ NSString *const MockCityId = @"beijing"; ...@@ -114,7 +114,7 @@ NSString *const MockCityId = @"beijing";
} }
- (void)testCatchNullInAttributes { - (void)testCatchNullInAttributes {
_client.captureNullExpection = ^(NSDictionary *att) { _client.captureNullExpection = ^(NSString *eventId, NSDictionary *att) {
NSCAssert([att[@"bussness_id"] integerValue] == 1244, @"testCatchNullInAttributes 没有捕获到有用信息"); NSCAssert([att[@"bussness_id"] integerValue] == 1244, @"testCatchNullInAttributes 没有捕获到有用信息");
}; };
NSDictionary *attributes = @{@"key": [NSNull null], NSDictionary *attributes = @{@"key": [NSNull null],
...@@ -142,6 +142,12 @@ NSString *const MockCityId = @"beijing"; ...@@ -142,6 +142,12 @@ NSString *const MockCityId = @"beijing";
[controller viewWillAppear:true]; [controller viewWillAppear:true];
[controller viewWillDisappear:true]; [controller viewWillDisappear:true];
[self paramUnNilCheck]; [self paramUnNilCheck];
NSArray *array = [[WMCacheService sharedInstance] fetchObjectAtDiskWithkey:PhobosCacheKey];
XCTAssertTrue(array.count != 0, @"PhobosCacheKey 下面应该有数据");
NSDictionary *dic = array[0][@"params"];
XCTAssertTrue([dic[@"referrer_id"] isEqualToString:@"rreferrerIdTest"], @"referrerId至少使用默认的空字符串");
} }
- (void)testSimulativePageViewEvent { - (void)testSimulativePageViewEvent {
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#pragma mark - SDK配置 #pragma mark - SDK配置
// Phobos在处理业务端传递来的参数时会检查是否某个value为空,如果为空会调用这个block以通知业务层,业务层可以上报这个异常,以助解决问题 // Phobos在处理业务端传递来的参数时会检查是否某个value为空,如果为空会调用这个block以通知业务层,业务层可以上报这个异常,以助解决问题
@property(nonatomic, copy) void (^captureNullExpection) (NSDictionary *info); @property(nonatomic, copy) void (^captureNullExpection) (NSString *eventId, NSDictionary *info);
/** /**
网络状态 wifi=1, mobile=0, 不连通=-1 网络状态 wifi=1, mobile=0, 不连通=-1
......
...@@ -304,7 +304,7 @@ static NSString *sdkVersion = @"110"; ...@@ -304,7 +304,7 @@ static NSString *sdkVersion = @"110";
* @since 0.0.1 * @since 0.0.1
*/ */
- (NSDictionary *)prepareDictionaryForEvent:(NSString *)eventId attributes:(NSDictionary *)attributes{ - (NSDictionary *)prepareDictionaryForEvent:(NSString *)eventId attributes:(NSDictionary *)attributes{
[self performSelectorInBackground:@selector(catchNullInAttributes:) withObject:attributes]; [self catchNullForEvent:eventId attributes:attributes];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
@try { @try {
NSString *currentTime = [PhobosUtil currentTime]; NSString *currentTime = [PhobosUtil currentTime];
...@@ -400,19 +400,21 @@ static NSString *sdkVersion = @"110"; ...@@ -400,19 +400,21 @@ static NSString *sdkVersion = @"110";
} }
#pragma mark - helpers #pragma mark - helpers
- (void)catchNullInAttributes:(NSDictionary *)attributes { - (void)catchNullForEvent:(NSString *)eventId attributes:(NSDictionary *)attributes {
@try { dispatch_async(dispatch_get_global_queue(0, 0), ^{
for (NSString *key in attributes.allKeys) { @try {
if ([attributes[key] isMemberOfClass:[NSNull class]]) { for (NSString *key in attributes.allKeys) {
if (self.captureNullExpection) { if ([attributes[key] isMemberOfClass:[NSNull class]]) {
self.captureNullExpection(attributes); if (self.captureNullExpection) {
self.captureNullExpection(eventId, attributes);
}
break;
} }
break;
} }
} @catch (NSException *exception) {
} }
} @catch (NSException *exception) { });
}
} }
@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