Authored by 朱小军

network错误增加百度域名访问诊断 review by 戴强

... ... @@ -194,38 +194,6 @@ typedef NS_ENUM(NSInteger, YHPointType) {
#define kYHEventReportClickContent @"CONTENT"
#define YOHOAppReportDefalutChannelNum @"2119" // 推广渠道号
// 运营商
#define kCarrierCodeChinaUnknown @"0" // 未知
#define kCarrierCodeChinaMobile @"1" // 中国移动
#define kCarrierCodeChinaTelecom @"2" // 中国电信
#define kCarrierCodeChinaUnicom @"3" // 中国联通
#define kCarrierCodeChinaTietong @"4" // 中国铁通
//上报参数的key
#define YOHOAppReportKeyAK @"ak"
#define YOHOAppReportKeyUDID @"udid"
#define YOHOAppReportKeyCH @"ch"
#define YOHOAppReportKeyOS @"os"
#define YOHOAppReportKeyOSV @"osv"
#define YOHOAppReportKeyDM @"dm"
#define YOHOAppReportKeyPS @"ps"
#define YOHOAppReportKeyAV @"av"
#define YOHOAppReportKeyAB @"ab"
#define YOHOAppReportKeyCA @"ca"
#define YOHOAppReportKeyNET @"net"
#define YOHOAppReportKeyTS @"ts"
#define YOHOAppReportKeyUID @"uid"
#define YOHOAppReportKeySID @"sid"
#define YOHOAppReportKeyPT @"pt"
#define YOHOAppReportKeyPN @"pn"
#define YOHOAppReportKeyPARAM @"param"
#define YOHOAppReportDefaultAPPKey @"yohobuy_ios"
#define IsNilOrNull(_ref) (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]))
... ... @@ -286,7 +254,8 @@ typedef NS_ENUM(NSInteger, YHPointType) {
#define YOHOAppReportKeyJsonKeyDataTypeDevice @"device" // 终端信息,包括终端的状态
#define YOHOAppReportKeyJsonKeyDataTypeStatus @"status" // 状态信息,包括一次操作时,用户的位置和网络等信息
#define YOHOAppReportKeyJsonKeyDataTypeEvents @"events" // 事件信息,包括用户的操作日志
#define YOHOAppReportKeyJsonKeyErrorTEC @"tec" // 第三方百度返回错误码
#define YOHOAppReportKeyJsonKeyErrorCTS @"cts" // 第三方百度返回错误码时间
// 当前网络状态
#define YOHOAppReportKeykNetWorkStatusUnknow @"0" // 未知
... ... @@ -337,6 +306,7 @@ typedef NS_ENUM(NSInteger, YHPointType) {
#define YOHOAppReportKeyOS @"os"
#define YOHOAppReportKeyOSV @"osv"
#define YOHOAppReportKeyDM @"dm"
#define YOHOAppReportKeyIDFA @"idfa"
#define YOHOAppReportKeyPS @"ps"
#define YOHOAppReportKeyAV @"av"
#define YOHOAppReportKeyAB @"ab"
... ...
... ... @@ -336,6 +336,7 @@
IsStrEmpty(appInfo.os)?@"":appInfo.os,YOHOAppReportKeyOS,
IsStrEmpty(appInfo.osv)?@"":appInfo.osv,YOHOAppReportKeyOSV,
IsStrEmpty(appInfo.dm)?@"":appInfo.dm,YOHOAppReportKeyDM,
IsStrEmpty(appInfo.idfa)?@"":appInfo.idfa,YOHOAppReportKeyIDFA,
nil];
return deviceInfo;
}
... ...
... ... @@ -24,6 +24,7 @@
@property (copy, nonatomic) NSString *uid; // 用户id
@property (copy, nonatomic) NSString *sid; // 会话id(由设备标识和启动时间戳做md5)
@property (copy, nonatomic) NSString *ts; // 时间戳
@property (copy, nonatomic) NSString *idfa; //设备idfa标识
-(void)resetSessionID;
... ...
... ... @@ -14,6 +14,7 @@
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <UIKit/UIKit.h>
#import <AdSupport/AdSupport.h>
#import "YH_EventUtil.h"
#import "YHEventReport.h"
#import "NSString+ER_URL.h"
... ... @@ -26,6 +27,7 @@
if (self) {
self.ps = @"0";
self.ca = [self getCurrentCa];
self.idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
}
return self;
... ...
... ... @@ -192,7 +192,15 @@ static NSString *kParamKeyType = @"type";
[eventDic setObject:data forKey:YOHOAppReportKeyPARAM];
}
[self pushData:eventDic dataType:YHEventReportDataTypeCustom];
if (type == YHPT_NETWORK) {
[self.eventDataSession getbaiduNetStatus:eventDic completionBlock:^(NSTimeInterval cts, NSInteger errCode) {
[eventDic setValue:[NSString stringWithFormat:@"%ld",(long)errCode] forKey:YOHOAppReportKeyJsonKeyErrorTEC];
[eventDic setValue:@(cts) forKey:YOHOAppReportKeyJsonKeyErrorCTS];
[self pushData:eventDic dataType:YHEventReportDataTypeCustom];
}];
} else {
[self pushData:eventDic dataType:YHEventReportDataTypeCustom];
}
}
- (void)pushCrashData:(NSDictionary*)data{
... ...
... ... @@ -25,4 +25,6 @@
*/
- (void) uploadPerformanceData:(id)parameters tag:(id)tag result:(void (^)(BOOL isSuc,id tag, NSError *error))result;
//图片or接口异常下百度连接状态上报
- (void)getbaiduNetStatus:(NSDictionary *)parameters completionBlock:(void (^)(NSTimeInterval cts, NSInteger errCode))diagnosisBlock;
@end
... ...
... ... @@ -18,12 +18,16 @@
#define kYOHOPerformanceReportURL @"http://app.yoho.cn/collect/v3"//@"http://172.16.6.108/collect/v2"
#define kYOHONetworkDiagnosisURL @"https://m.baidu.com"
@interface YH_EventDataSession()
@property (nonatomic,strong)NSMutableURLRequest *uploadEventRequest;
@property (nonatomic,strong)NSMutableURLRequest *uploadPerformanceRequest;
@property (nonatomic,strong)NSMutableURLRequest *networkDiagnosisRequest;
@property (nonatomic,strong)NSURLSession *uploadSession;
@property (nonatomic,assign)BOOL canUpload;
... ... @@ -114,6 +118,35 @@
#endif
}
#pragma mark 百度连接状态诊断
- (void)getbaiduNetStatus:(NSDictionary *)parameters completionBlock:(void (^)(NSTimeInterval cts, NSInteger errCode))diagnosisBlock
{
if (!diagnosisBlock) {
return;
}
NSDate *startDate = [NSDate date];
NSURLSessionDataTask *task = [self.uploadSession dataTaskWithRequest:self.networkDiagnosisRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDate *endDate = [NSDate date];
long durationTime = [endDate timeIntervalSinceDate:startDate] * 1000;
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if (error) {
NSInteger ect = 0;
if (error.code == 0) {
ect = -1;
} else {
ect = error.code;
}
diagnosisBlock(durationTime,ect);
}else{
diagnosisBlock(durationTime,httpResponse.statusCode);
}
}];
[task resume];
}
#pragma mark - private
-(NSData *)getBodyData:(id)param
{
... ... @@ -166,6 +199,15 @@
return _uploadPerformanceRequest;
}
- (NSMutableURLRequest *)networkDiagnosisRequest {
if (!_networkDiagnosisRequest) {
NSURL *url = [NSURL URLWithString:kYOHONetworkDiagnosisURL];
_networkDiagnosisRequest = [NSMutableURLRequest requestWithURL:url];
}
return _networkDiagnosisRequest;
}
#pragma mark - NSNotificationCenter
- (void)networkStateChange
... ...