解决了语音上传到问题,接下来要解决下载播放问题
This commit is contained in:
60
Pods/Qiniu/QiniuSDK/Collect/QNReportConfig.h
generated
Normal file
60
Pods/Qiniu/QiniuSDK/Collect/QNReportConfig.h
generated
Normal file
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// QNReportConfig.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by 杨森 on 2020/7/14.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QNReportConfig : NSObject
|
||||
|
||||
- (id)init __attribute__((unavailable("Use sharedInstance: instead.")));
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
/**
|
||||
* 是否开启sdk上传信息搜集 默认为YES
|
||||
*/
|
||||
@property (nonatomic, assign, getter=isReportEnable) BOOL reportEnable;
|
||||
|
||||
/**
|
||||
* 每次上传时间间隔 单位:分钟 默认为0.5分钟
|
||||
*/
|
||||
@property (nonatomic, assign) double interval;
|
||||
|
||||
/**
|
||||
* 记录文件大于 uploadThreshold 会触发上传,单位:字节 默认为16 * 1024
|
||||
*/
|
||||
@property (nonatomic, assign) uint64_t uploadThreshold;
|
||||
|
||||
/**
|
||||
* 记录文件最大值 要大于 uploadThreshold 单位:字节 默认为20 * 1024 * 1024
|
||||
*/
|
||||
@property (nonatomic, assign) uint64_t maxRecordFileSize;
|
||||
|
||||
/**
|
||||
* 记录文件所在文件夹目录 默认为:.../沙盒/Library/Caches/com.qiniu.report
|
||||
*/
|
||||
@property (nonatomic, copy) NSString *recordDirectory;
|
||||
|
||||
/**
|
||||
* 信息上报服务器地址
|
||||
*/
|
||||
@property (nonatomic, copy, readonly) NSString *serverURL;
|
||||
|
||||
/**
|
||||
* 信息上报服务器地址 host
|
||||
*/
|
||||
@property (nonatomic, copy, readonly) NSString *serverHost;
|
||||
|
||||
/**
|
||||
* 信息上报请求超时时间 单位:秒 默认为10秒
|
||||
*/
|
||||
@property (nonatomic, assign, readonly) NSTimeInterval timeoutInterval;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
42
Pods/Qiniu/QiniuSDK/Collect/QNReportConfig.m
generated
Normal file
42
Pods/Qiniu/QiniuSDK/Collect/QNReportConfig.m
generated
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// QNReportConfig.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by 杨森 on 2020/7/14.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNReportConfig.h"
|
||||
#import "QNConfig.h"
|
||||
#import "QNUtils.h"
|
||||
|
||||
@implementation QNReportConfig
|
||||
|
||||
+ (instancetype)sharedInstance {
|
||||
|
||||
static QNReportConfig *sharedInstance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [[self alloc] init];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_reportEnable = YES;
|
||||
_interval = 0.5;
|
||||
_serverHost = kQNUpLogHost;
|
||||
_recordDirectory = [NSString stringWithFormat:@"%@/report", [QNUtils sdkCacheDirectory]];
|
||||
_maxRecordFileSize = 20 * 1024 * 1024;
|
||||
_uploadThreshold = 16 * 1024;
|
||||
_timeoutInterval = 10;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)serverURL {
|
||||
return [NSString stringWithFormat:@"https://%@/log/4?compressed=gzip", _serverHost];
|
||||
}
|
||||
@end
|
||||
143
Pods/Qiniu/QiniuSDK/Collect/QNReportItem.h
generated
Normal file
143
Pods/Qiniu/QiniuSDK/Collect/QNReportItem.h
generated
Normal file
@@ -0,0 +1,143 @@
|
||||
//
|
||||
// QNReportItem.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/5/12.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNUploadInfoReporter.h"
|
||||
#import "QNResponseInfo.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QNReportItem : NSObject
|
||||
|
||||
+ (instancetype)item;
|
||||
|
||||
/// 设置打点日志字段
|
||||
/// @param value log value
|
||||
/// @param key log key
|
||||
- (void)setReportValue:(id _Nullable)value forKey:(NSString * _Nullable)key;
|
||||
|
||||
/// 移除打点日志字段
|
||||
/// @param key log key
|
||||
- (void)removeReportValueForKey:(NSString * _Nullable)key;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface QNUploadInfoReporter(ReportItem)
|
||||
|
||||
- (void)reportItem:(QNReportItem *)item token:(NSString *)token;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface QNResponseInfo(Report)
|
||||
|
||||
@property(nonatomic, assign, readonly)NSNumber *requestReportStatusCode;
|
||||
@property(nonatomic, copy, readonly)NSString *requestReportErrorType;
|
||||
|
||||
@property(nonatomic, copy, readonly)NSString *qualityResult;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
//MARK:-- 日志类型
|
||||
extern NSString *const QNReportLogTypeRequest;
|
||||
extern NSString *const QNReportLogTypeBlock;
|
||||
extern NSString *const QNReportLogTypeQuality;
|
||||
|
||||
//MARK:-- 请求信息打点⽇志
|
||||
extern NSString *const QNReportRequestKeyLogType;
|
||||
extern NSString *const QNReportRequestKeyUpTime;
|
||||
extern NSString *const QNReportRequestKeyStatusCode;
|
||||
extern NSString *const QNReportRequestKeyRequestId;
|
||||
extern NSString *const QNReportRequestKeyHost;
|
||||
extern NSString *const QNReportRequestKeyHttpVersion;
|
||||
extern NSString *const QNReportRequestKeyRemoteIp;
|
||||
extern NSString *const QNReportRequestKeyPort;
|
||||
extern NSString *const QNReportRequestKeyTargetBucket;
|
||||
extern NSString *const QNReportRequestKeyTargetKey;
|
||||
extern NSString *const QNReportRequestKeyTotalElapsedTime;
|
||||
extern NSString *const QNReportRequestKeyDnsElapsedTime;
|
||||
extern NSString *const QNReportRequestKeyConnectElapsedTime;
|
||||
extern NSString *const QNReportRequestKeyTLSConnectElapsedTime;
|
||||
extern NSString *const QNReportRequestKeyRequestElapsedTime;
|
||||
extern NSString *const QNReportRequestKeyWaitElapsedTime;
|
||||
extern NSString *const QNReportRequestKeyResponseElapsedTime;
|
||||
extern NSString *const QNReportRequestKeyFileOffset;
|
||||
extern NSString *const QNReportRequestKeyBytesSent;
|
||||
extern NSString *const QNReportRequestKeyBytesTotal;
|
||||
extern NSString *const QNReportRequestKeyPid;
|
||||
extern NSString *const QNReportRequestKeyTid;
|
||||
extern NSString *const QNReportRequestKeyTargetRegionId;
|
||||
extern NSString *const QNReportRequestKeyCurrentRegionId;
|
||||
extern NSString *const QNReportRequestKeyErrorType;
|
||||
extern NSString *const QNReportRequestKeyErrorDescription;
|
||||
extern NSString *const QNReportRequestKeyUpType;
|
||||
extern NSString *const QNReportRequestKeyOsName;
|
||||
extern NSString *const QNReportRequestKeyOsVersion;
|
||||
extern NSString *const QNReportRequestKeySDKName;
|
||||
extern NSString *const QNReportRequestKeySDKVersion;
|
||||
extern NSString *const QNReportRequestKeyClientTime;
|
||||
extern NSString *const QNReportRequestKeyHttpClient;
|
||||
extern NSString *const QNReportRequestKeyNetworkType;
|
||||
extern NSString *const QNReportRequestKeySignalStrength;
|
||||
extern NSString *const QNReportRequestKeyPrefetchedDnsSource;
|
||||
extern NSString *const QNReportRequestKeyDnsSource;
|
||||
extern NSString *const QNReportRequestKeyDnsErrorMessage;
|
||||
extern NSString *const QNReportRequestKeyPrefetchedBefore;
|
||||
extern NSString *const QNReportRequestKeyPrefetchedErrorMessage;
|
||||
extern NSString *const QNReportRequestKeyNetworkMeasuring;
|
||||
extern NSString *const QNReportRequestKeyPerceptiveSpeed;
|
||||
extern NSString *const QNReportRequestKeyHijacking;
|
||||
|
||||
//MARK:-- 分块上传统计⽇志
|
||||
extern NSString *const QNReportBlockKeyLogType;
|
||||
extern NSString *const QNReportBlockKeyUpTime;
|
||||
extern NSString *const QNReportBlockKeyTargetBucket;
|
||||
extern NSString *const QNReportBlockKeyTargetKey;
|
||||
extern NSString *const QNReportBlockKeyTargetRegionId;
|
||||
extern NSString *const QNReportBlockKeyCurrentRegionId;
|
||||
extern NSString *const QNReportBlockKeyTotalElapsedTime;
|
||||
extern NSString *const QNReportBlockKeyBytesSent;
|
||||
extern NSString *const QNReportBlockKeyRecoveredFrom;
|
||||
extern NSString *const QNReportBlockKeyFileSize;
|
||||
extern NSString *const QNReportBlockKeyPid;
|
||||
extern NSString *const QNReportBlockKeyTid;
|
||||
extern NSString *const QNReportBlockKeyUpApiVersion;
|
||||
extern NSString *const QNReportBlockKeyClientTime;
|
||||
extern NSString *const QNReportBlockKeyOsName;
|
||||
extern NSString *const QNReportBlockKeyOsVersion;
|
||||
extern NSString *const QNReportBlockKeySDKName;
|
||||
extern NSString *const QNReportBlockKeySDKVersion;
|
||||
extern NSString *const QNReportBlockKeyPerceptiveSpeed;
|
||||
extern NSString *const QNReportBlockKeyHijacking;
|
||||
|
||||
//MARK:-- 上传质量统计
|
||||
extern NSString *const QNReportQualityKeyLogType;
|
||||
extern NSString *const QNReportQualityKeyUpType;
|
||||
extern NSString *const QNReportQualityKeyUpTime;
|
||||
extern NSString *const QNReportQualityKeyResult;
|
||||
extern NSString *const QNReportQualityKeyTargetBucket;
|
||||
extern NSString *const QNReportQualityKeyTargetKey;
|
||||
extern NSString *const QNReportQualityKeyTotalElapsedTime;
|
||||
extern NSString *const QNReportQualityKeyUcQueryElapsedTime;
|
||||
extern NSString *const QNReportQualityKeyRequestsCount;
|
||||
extern NSString *const QNReportQualityKeyRegionsCount;
|
||||
extern NSString *const QNReportQualityKeyBytesSent;
|
||||
extern NSString *const QNReportQualityKeyFileSize;
|
||||
extern NSString *const QNReportQualityKeyCloudType;
|
||||
extern NSString *const QNReportQualityKeyErrorType;
|
||||
extern NSString *const QNReportQualityKeyErrorDescription;
|
||||
extern NSString *const QNReportQualityKeyOsName;
|
||||
extern NSString *const QNReportQualityKeyOsVersion;
|
||||
extern NSString *const QNReportQualityKeySDKName;
|
||||
extern NSString *const QNReportQualityKeySDKVersion;
|
||||
extern NSString *const QNReportQualityKeyPerceptiveSpeed;
|
||||
extern NSString *const QNReportQualityKeyHijacking;
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
257
Pods/Qiniu/QiniuSDK/Collect/QNReportItem.m
generated
Normal file
257
Pods/Qiniu/QiniuSDK/Collect/QNReportItem.m
generated
Normal file
@@ -0,0 +1,257 @@
|
||||
//
|
||||
// QNReportItem.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/5/12.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNReportItem.h"
|
||||
#import "QNAsyncRun.h"
|
||||
#import "QNLogUtil.h"
|
||||
|
||||
@interface QNReportItem()
|
||||
|
||||
@property(nonatomic, strong)NSMutableDictionary *keyValues;
|
||||
|
||||
@end
|
||||
@implementation QNReportItem
|
||||
|
||||
+ (instancetype)item{
|
||||
QNReportItem *item = [[QNReportItem alloc] init];
|
||||
return item;
|
||||
}
|
||||
|
||||
- (instancetype)init{
|
||||
if (self = [super init]) {
|
||||
[self initData];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initData{
|
||||
_keyValues = [NSMutableDictionary dictionary];
|
||||
}
|
||||
|
||||
- (void)setReportValue:(id _Nullable)value forKey:(NSString * _Nullable)key{
|
||||
if (!value || !key || ![key isKindOfClass:[NSString class]]) {
|
||||
return;
|
||||
}
|
||||
if ([value isKindOfClass:[NSString class]] && [(NSString *)value length] > 1024) {
|
||||
value = [(NSString *)value substringToIndex:1024];
|
||||
}
|
||||
[self.keyValues setValue:value forKey:key];
|
||||
}
|
||||
|
||||
- (void)removeReportValueForKey:(NSString * _Nullable)key{
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
[self.keyValues removeObjectForKey:key];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)toJson{
|
||||
|
||||
NSString *jsonString = @"{}";
|
||||
if (!self.keyValues || self.keyValues.count == 0) {
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.keyValues
|
||||
options:NSJSONWritingFragmentsAllowed
|
||||
error:nil];
|
||||
if (!jsonData) {
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation QNUploadInfoReporter(ReportItem)
|
||||
|
||||
- (void)reportItem:(QNReportItem *)item token:(NSString *)token{
|
||||
NSString *itemJsonString = [item toJson];
|
||||
QNLogInfo(@"up log:%@", itemJsonString);
|
||||
if (itemJsonString && ![itemJsonString isEqualToString:@"{}"]) {
|
||||
[kQNReporter report:itemJsonString token:token];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation QNResponseInfo(Report)
|
||||
|
||||
- (NSNumber *)requestReportStatusCode{
|
||||
return @(self.statusCode);
|
||||
}
|
||||
|
||||
- (NSString *)requestReportErrorType{
|
||||
NSString *errorType = nil;
|
||||
if (self.statusCode == -1){
|
||||
errorType = @"network_error";
|
||||
} else if (self.statusCode == kQNLocalIOError){
|
||||
errorType = @"local_io_error";
|
||||
} else if (self.statusCode == 100){
|
||||
errorType = @"protocol_error";
|
||||
} else if (self.statusCode > 199 && self.statusCode < 300) {
|
||||
// NSURLErrorFailingURLErrorKey
|
||||
} else if (self.statusCode > 299){
|
||||
errorType = @"response_error";
|
||||
} else if (self.statusCode == -1003){
|
||||
errorType = @"unknown_host";
|
||||
} else if (self.statusCode == -1009){
|
||||
errorType = @"network_slow";
|
||||
} else if (self.statusCode == -1001){
|
||||
errorType = @"timeout";
|
||||
} else if (self.statusCode == -1004){
|
||||
errorType = @"cannot_connect_to_host";
|
||||
} else if (self.statusCode == -1005 || self.statusCode == -1021){
|
||||
errorType = @"transmission_error";
|
||||
} else if ((self.statusCode <= -1200 && self.statusCode >= -1206) || self.statusCode == -2000 || self.statusCode == -9807){
|
||||
errorType = @"ssl_error";
|
||||
} else if (self.statusCode == -1015 || self.statusCode == -1016 || self.statusCode == -1017){
|
||||
errorType = @"parse_error";
|
||||
} else if (self.statusCode == -1007 || self.statusCode == -1010 || self.statusCode == kQNMaliciousResponseError){
|
||||
errorType = @"malicious_response";
|
||||
} else if (self.statusCode == kQNUnexpectedSysCallError
|
||||
|| (self.statusCode > -1130 && self.statusCode <= -1010)){
|
||||
errorType = @"unexpected_syscall_error";
|
||||
} else if (self.statusCode == kQNRequestCancelled
|
||||
|| self.statusCode == NSURLErrorCancelled){
|
||||
errorType = @"user_canceled";
|
||||
} else {
|
||||
errorType = @"unknown_error";
|
||||
}
|
||||
return errorType;
|
||||
}
|
||||
|
||||
- (NSString *)qualityResult{
|
||||
|
||||
NSString *result = nil;
|
||||
|
||||
if (self.statusCode > 199 && self.statusCode < 300) {
|
||||
result = @"ok";
|
||||
} else if (self.statusCode > 399 &&
|
||||
(self.statusCode < 500 || self.statusCode == 573 || self.statusCode == 579 ||
|
||||
self.statusCode == 608 || self.statusCode == 612 || self.statusCode == 614 || self.statusCode == 630 || self.statusCode == 631 ||
|
||||
self.statusCode == 701)) {
|
||||
result = @"bad_request";
|
||||
} else if (self.statusCode == kQNZeroDataSize){
|
||||
result = @"zero_size_file";
|
||||
} else if (self.statusCode == kQNFileError){
|
||||
result = @"invalid_file";
|
||||
} else if (self.statusCode == kQNInvalidToken
|
||||
|| self.statusCode == kQNInvalidArgument){
|
||||
result = @"invalid_args";
|
||||
}
|
||||
|
||||
if (result == nil) {
|
||||
result = [self requestReportErrorType];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
//MARK:-- 日志类型
|
||||
NSString * const QNReportLogTypeRequest = @"request";
|
||||
NSString * const QNReportLogTypeBlock = @"block";
|
||||
NSString * const QNReportLogTypeQuality = @"quality";
|
||||
|
||||
|
||||
//MARK:-- 请求信息打点⽇志
|
||||
NSString * const QNReportRequestKeyLogType = @"log_type";
|
||||
NSString * const QNReportRequestKeyUpTime = @"up_time";
|
||||
NSString * const QNReportRequestKeyStatusCode = @"status_code";
|
||||
NSString * const QNReportRequestKeyRequestId = @"req_id";
|
||||
NSString * const QNReportRequestKeyHost = @"host";
|
||||
NSString * const QNReportRequestKeyHttpVersion = @"http_version";
|
||||
NSString * const QNReportRequestKeyRemoteIp = @"remote_ip";
|
||||
NSString * const QNReportRequestKeyPort = @"port";
|
||||
NSString * const QNReportRequestKeyTargetBucket = @"target_bucket";
|
||||
NSString * const QNReportRequestKeyTargetKey = @"target_key";
|
||||
NSString * const QNReportRequestKeyTotalElapsedTime = @"total_elapsed_time";
|
||||
NSString * const QNReportRequestKeyDnsElapsedTime = @"dns_elapsed_time";
|
||||
NSString * const QNReportRequestKeyConnectElapsedTime = @"connect_elapsed_time";
|
||||
NSString * const QNReportRequestKeyTLSConnectElapsedTime = @"tls_connect_elapsed_time";
|
||||
NSString * const QNReportRequestKeyRequestElapsedTime = @"request_elapsed_time";
|
||||
NSString * const QNReportRequestKeyWaitElapsedTime = @"wait_elapsed_time";
|
||||
NSString * const QNReportRequestKeyResponseElapsedTime = @"response_elapsed_time";
|
||||
NSString * const QNReportRequestKeyFileOffset = @"file_offset";
|
||||
NSString * const QNReportRequestKeyBytesSent = @"bytes_sent";
|
||||
NSString * const QNReportRequestKeyBytesTotal = @"bytes_total";
|
||||
NSString * const QNReportRequestKeyPid = @"pid";
|
||||
NSString * const QNReportRequestKeyTid = @"tid";
|
||||
NSString * const QNReportRequestKeyTargetRegionId = @"target_region_id";
|
||||
NSString * const QNReportRequestKeyCurrentRegionId = @"current_region_id";
|
||||
NSString * const QNReportRequestKeyErrorType = @"error_type";
|
||||
NSString * const QNReportRequestKeyErrorDescription = @"error_description";
|
||||
NSString * const QNReportRequestKeyUpType = @"up_type";
|
||||
NSString * const QNReportRequestKeyOsName = @"os_name";
|
||||
NSString * const QNReportRequestKeyOsVersion = @"os_version";
|
||||
NSString * const QNReportRequestKeySDKName = @"sdk_name";
|
||||
NSString * const QNReportRequestKeySDKVersion = @"sdk_version";
|
||||
NSString * const QNReportRequestKeyClientTime = @"client_time";
|
||||
NSString * const QNReportRequestKeyHttpClient = @"http_client";
|
||||
NSString * const QNReportRequestKeyNetworkType = @"network_type";
|
||||
NSString * const QNReportRequestKeySignalStrength = @"signal_strength";
|
||||
NSString * const QNReportRequestKeyPrefetchedDnsSource = @"prefetched_dns_source";
|
||||
NSString * const QNReportRequestKeyDnsSource = @"dns_source";
|
||||
NSString * const QNReportRequestKeyDnsErrorMessage = @"dns_error_message";
|
||||
NSString * const QNReportRequestKeyPrefetchedBefore = @"prefetched_before";
|
||||
NSString * const QNReportRequestKeyPrefetchedErrorMessage = @"prefetched_error_message";
|
||||
NSString * const QNReportRequestKeyNetworkMeasuring = @"network_measuring";
|
||||
NSString * const QNReportRequestKeyPerceptiveSpeed = @"perceptive_speed";
|
||||
NSString * const QNReportRequestKeyHijacking = @"hijacking";
|
||||
|
||||
//MARK:-- 分块上传统计⽇志
|
||||
NSString * const QNReportBlockKeyLogType = @"log_type";
|
||||
NSString * const QNReportBlockKeyUpTime = @"up_time";
|
||||
NSString * const QNReportBlockKeyTargetBucket = @"target_bucket";
|
||||
NSString * const QNReportBlockKeyTargetKey = @"target_key";
|
||||
NSString * const QNReportBlockKeyTargetRegionId = @"target_region_id";
|
||||
NSString * const QNReportBlockKeyCurrentRegionId = @"current_region_id";
|
||||
NSString * const QNReportBlockKeyTotalElapsedTime = @"total_elapsed_time";
|
||||
NSString * const QNReportBlockKeyBytesSent = @"bytes_sent";
|
||||
NSString * const QNReportBlockKeyRecoveredFrom = @"recovered_from";
|
||||
NSString * const QNReportBlockKeyFileSize = @"file_size";
|
||||
NSString * const QNReportBlockKeyPid = @"pid";
|
||||
NSString * const QNReportBlockKeyTid = @"tid";
|
||||
NSString * const QNReportBlockKeyUpApiVersion = @"up_api_version";
|
||||
NSString * const QNReportBlockKeyClientTime = @"client_time";
|
||||
NSString * const QNReportBlockKeyOsName = @"os_name";
|
||||
NSString * const QNReportBlockKeyOsVersion = @"os_version";
|
||||
NSString * const QNReportBlockKeySDKName = @"sdk_name";
|
||||
NSString * const QNReportBlockKeySDKVersion = @"sdk_version";
|
||||
NSString * const QNReportBlockKeyPerceptiveSpeed = @"perceptive_speed";
|
||||
NSString * const QNReportBlockKeyHijacking = @"hijacking";
|
||||
|
||||
|
||||
//MARK:-- 上传质量统计
|
||||
NSString * const QNReportQualityKeyLogType = @"log_type";
|
||||
NSString * const QNReportQualityKeyUpType = @"up_type";
|
||||
NSString * const QNReportQualityKeyUpTime = @"up_time";
|
||||
NSString * const QNReportQualityKeyResult = @"result";
|
||||
NSString * const QNReportQualityKeyTargetBucket = @"target_bucket";
|
||||
NSString * const QNReportQualityKeyTargetKey = @"target_key";
|
||||
NSString * const QNReportQualityKeyTotalElapsedTime = @"total_elapsed_time";
|
||||
NSString * const QNReportQualityKeyUcQueryElapsedTime = @"uc_query_elapsed_time";
|
||||
NSString * const QNReportQualityKeyRequestsCount = @"requests_count";
|
||||
NSString * const QNReportQualityKeyRegionsCount = @"regions_count";
|
||||
NSString * const QNReportQualityKeyBytesSent = @"bytes_sent";
|
||||
NSString * const QNReportQualityKeyFileSize = @"file_size";
|
||||
NSString * const QNReportQualityKeyCloudType = @"cloud_type";
|
||||
NSString * const QNReportQualityKeyErrorType = @"error_type";
|
||||
NSString * const QNReportQualityKeyErrorDescription = @"error_description";
|
||||
NSString * const QNReportQualityKeyOsName = @"os_name";
|
||||
NSString * const QNReportQualityKeyOsVersion = @"os_version";
|
||||
NSString * const QNReportQualityKeySDKName = @"sdk_name";
|
||||
NSString * const QNReportQualityKeySDKVersion = @"sdk_version";
|
||||
NSString * const QNReportQualityKeyPerceptiveSpeed = @"perceptive_speed";
|
||||
NSString * const QNReportQualityKeyHijacking = @"hijacking";
|
||||
36
Pods/Qiniu/QiniuSDK/Collect/QNUploadInfoReporter.h
generated
Normal file
36
Pods/Qiniu/QiniuSDK/Collect/QNUploadInfoReporter.h
generated
Normal file
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// QNUploadInfoReporter.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by WorkSpace_Sun on 2019/6/24.
|
||||
// Copyright © 2019 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#if __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define kQNReporter [QNUploadInfoReporter sharedInstance]
|
||||
@interface QNUploadInfoReporter : NSObject
|
||||
|
||||
- (id)init __attribute__((unavailable("Use sharedInstance: instead.")));
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
/**
|
||||
* 上报统计信息
|
||||
*
|
||||
* @param jsonString 需要记录的json字符串
|
||||
* @param token 上传凭证
|
||||
*
|
||||
*/
|
||||
- (void)report:(NSString *)jsonString token:(NSString *)token;
|
||||
|
||||
/**
|
||||
* 清空统计信息
|
||||
*/
|
||||
- (void)clean;
|
||||
|
||||
@end
|
||||
|
||||
242
Pods/Qiniu/QiniuSDK/Collect/QNUploadInfoReporter.m
generated
Normal file
242
Pods/Qiniu/QiniuSDK/Collect/QNUploadInfoReporter.m
generated
Normal file
@@ -0,0 +1,242 @@
|
||||
//
|
||||
// QNUploadInfoReporter.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by WorkSpace_Sun on 2019/6/24.
|
||||
// Copyright © 2019 Qiniu. All rights reserved.
|
||||
//
|
||||
#import "QNDefine.h"
|
||||
#import "QNZoneInfo.h"
|
||||
#import "QNUploadInfoReporter.h"
|
||||
#import "QNResponseInfo.h"
|
||||
#import "QNUtils.h"
|
||||
#import "QNFile.h"
|
||||
#import "QNUpToken.h"
|
||||
#import "QNUserAgent.h"
|
||||
#import "QNAsyncRun.h"
|
||||
#import "QNVersion.h"
|
||||
#import "QNReportConfig.h"
|
||||
#import "NSData+QNGZip.h"
|
||||
#import "QNTransactionManager.h"
|
||||
#import "QNRequestTransaction.h"
|
||||
|
||||
#define kQNUplogDelayReportTransactionName @"com.qiniu.uplog"
|
||||
|
||||
@interface QNUploadInfoReporter ()
|
||||
|
||||
@property (nonatomic, strong) QNReportConfig *config;
|
||||
@property (nonatomic, assign) NSTimeInterval lastReportTime;
|
||||
@property (nonatomic, strong) NSString *recorderFilePath;
|
||||
@property (nonatomic, strong) NSString *recorderTempFilePath;
|
||||
@property (nonatomic, copy) NSString *X_Log_Client_Id;
|
||||
|
||||
@property (nonatomic, strong) QNRequestTransaction *transaction;
|
||||
@property (nonatomic, assign) BOOL isReporting;
|
||||
|
||||
@property (nonatomic, strong) dispatch_queue_t recordQueue;
|
||||
@property (nonatomic, strong) dispatch_semaphore_t semaphore;
|
||||
@end
|
||||
|
||||
@implementation QNUploadInfoReporter
|
||||
|
||||
+ (instancetype)sharedInstance {
|
||||
|
||||
static QNUploadInfoReporter *sharedInstance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedInstance = [[self alloc] init];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_config = [QNReportConfig sharedInstance];
|
||||
_lastReportTime = 0;
|
||||
_recorderFilePath = [NSString stringWithFormat:@"%@/%@", _config.recordDirectory, @"qiniu.log"];
|
||||
_recorderTempFilePath = [NSString stringWithFormat:@"%@/%@", _config.recordDirectory, @"qiniuTemp.log"];
|
||||
_recordQueue = dispatch_queue_create("com.qiniu.reporter", DISPATCH_QUEUE_SERIAL);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)clean {
|
||||
[self cleanRecorderFile];
|
||||
[self cleanTempRecorderFile];
|
||||
}
|
||||
|
||||
- (void)cleanRecorderFile {
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
if ([manager fileExistsAtPath:_recorderFilePath]) {
|
||||
NSError *error = nil;
|
||||
[manager removeItemAtPath:_recorderFilePath error:&error];
|
||||
if (error) {
|
||||
NSLog(@"remove recorder file failed: %@", error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cleanTempRecorderFile {
|
||||
NSFileManager *manager = [NSFileManager defaultManager];
|
||||
if ([manager fileExistsAtPath:_recorderTempFilePath]) {
|
||||
NSError *error = nil;
|
||||
[manager removeItemAtPath:_recorderTempFilePath error:&error];
|
||||
if (error) {
|
||||
NSLog(@"remove recorder temp file failed: %@", error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)checkReportAvailable {
|
||||
if (!_config.isReportEnable) {
|
||||
return NO;
|
||||
}
|
||||
if (_config.maxRecordFileSize <= _config.uploadThreshold) {
|
||||
NSLog(@"maxRecordFileSize must be larger than uploadThreshold");
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)report:(NSString *)jsonString token:(NSString *)token {
|
||||
|
||||
if (![self checkReportAvailable] || !jsonString || !token || token.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 串行队列处理文件读写
|
||||
dispatch_async(self.recordQueue, ^{
|
||||
[kQNReporter saveReportJsonString:jsonString];
|
||||
[kQNReporter reportToServerIfNeeded:token];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)saveReportJsonString:(NSString *)jsonString {
|
||||
NSString *finalRecordInfo = [jsonString stringByAppendingString:@"\n"];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
if (![fileManager fileExistsAtPath:self.recorderFilePath]) {
|
||||
// 如果recordFile不存在,创建文件并写入首行,首次不上传
|
||||
[finalRecordInfo writeToFile:_recorderFilePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
||||
} else {
|
||||
NSDictionary *recorderFileAttr = [fileManager attributesOfItemAtPath:self.recorderFilePath error:nil];
|
||||
if ([recorderFileAttr fileSize] > self.config.maxRecordFileSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSFileHandle *fileHandler = nil;
|
||||
@try {
|
||||
// 上传信息写入recorder文件
|
||||
fileHandler = [NSFileHandle fileHandleForUpdatingAtPath:_recorderFilePath];
|
||||
[fileHandler seekToEndOfFile];
|
||||
[fileHandler writeData: [finalRecordInfo dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"NSFileHandle cannot write data: %@", exception.description);
|
||||
} @finally {
|
||||
[fileHandler closeFile];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)reportToServerIfNeeded:(NSString *)tokenString {
|
||||
BOOL needToReport = NO;
|
||||
long currentTime = [[NSDate date] timeIntervalSince1970];
|
||||
long interval = self.config.interval * 10;
|
||||
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSDictionary *recorderFileAttr = [fileManager attributesOfItemAtPath:self.recorderFilePath error:nil];
|
||||
if ([fileManager fileExistsAtPath:self.recorderTempFilePath]) {
|
||||
needToReport = YES;
|
||||
} else if ((self.lastReportTime == 0 || (currentTime - self.lastReportTime) >= interval || [recorderFileAttr fileSize] > self.config.uploadThreshold) &&
|
||||
([fileManager moveItemAtPath:self.recorderFilePath toPath:self.recorderTempFilePath error:nil])) {
|
||||
needToReport = YES;
|
||||
}
|
||||
|
||||
if (needToReport && !self.isReporting) {
|
||||
[self reportToServer:tokenString];
|
||||
} else {
|
||||
// 有未上传日志存在,则 interval 时间后再次重试一次
|
||||
if (![fileManager fileExistsAtPath:self.recorderFilePath] || [recorderFileAttr fileSize] == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSArray *transactionList = [kQNTransactionManager transactionsForName:kQNUplogDelayReportTransactionName];
|
||||
if (transactionList != nil && transactionList.count > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (transactionList != nil && transactionList.count == 1) {
|
||||
QNTransaction *transaction = transactionList.firstObject;
|
||||
if (transaction != nil && !transaction.isExecuting) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QNTransaction *transaction = [QNTransaction transaction:kQNUplogDelayReportTransactionName after:interval action:^{
|
||||
[kQNReporter reportToServerIfNeeded:tokenString];
|
||||
}];
|
||||
[kQNTransactionManager addTransaction:transaction];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)reportToServer:(NSString *)tokenString {
|
||||
if (tokenString == nil) {
|
||||
return;
|
||||
}
|
||||
QNUpToken *token = [QNUpToken parse:tokenString];
|
||||
if (!token.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSData *logData = [self getLogData];
|
||||
if (logData == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.isReporting = YES;
|
||||
logData = [NSData qn_gZip:logData];
|
||||
QNRequestTransaction *transaction = [self createUploadRequestTransaction:token];
|
||||
[transaction reportLog:logData logClientId:self.X_Log_Client_Id complete:^(QNResponseInfo * _Nullable responseInfo, QNUploadRegionRequestMetrics * _Nullable metrics, NSDictionary * _Nullable response) {
|
||||
if (responseInfo.isOK) {
|
||||
self.lastReportTime = [[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970];
|
||||
if (!self.X_Log_Client_Id) {
|
||||
self.X_Log_Client_Id = responseInfo.responseHeader[@"x-log-client-id"];
|
||||
}
|
||||
[self cleanTempRecorderFile];
|
||||
} else {
|
||||
NSLog(@"upload info report failed: %@", responseInfo);
|
||||
}
|
||||
|
||||
self.isReporting = NO;
|
||||
[self destroyUploadRequestTransaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSData *)getLogData {
|
||||
return [NSData dataWithContentsOfFile:_recorderTempFilePath];
|
||||
}
|
||||
|
||||
- (QNRequestTransaction *)createUploadRequestTransaction:(QNUpToken *)token{
|
||||
if (self.config.serverURL) {
|
||||
|
||||
}
|
||||
NSArray *hosts = nil;
|
||||
if (self.config.serverHost) {
|
||||
hosts = @[self.config.serverHost];
|
||||
}
|
||||
QNRequestTransaction *transaction = [[QNRequestTransaction alloc] initWithHosts:hosts
|
||||
regionId:QNZoneInfoEmptyRegionId
|
||||
token:token];
|
||||
self.transaction = transaction;
|
||||
return transaction;
|
||||
}
|
||||
|
||||
- (void)destroyUploadRequestTransaction:(QNRequestTransaction *)transaction{
|
||||
self.transaction = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user