解决了语音上传到问题,接下来要解决下载播放问题
This commit is contained in:
37
Pods/Qiniu/QiniuSDK/Http/NetworkStatus/QNNetworkStatusManager.h
generated
Normal file
37
Pods/Qiniu/QiniuSDK/Http/NetworkStatus/QNNetworkStatusManager.h
generated
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// QNNetworkStatusManager.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/11/17.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QNNetworkStatus : NSObject
|
||||
|
||||
/// 网速 单位:kb/s 默认:200kb/s
|
||||
@property(nonatomic, assign, readonly)int speed;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#define kQNNetworkStatusManager [QNNetworkStatusManager sharedInstance]
|
||||
@interface QNNetworkStatusManager : NSObject
|
||||
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
+ (NSString *)getNetworkStatusType:(NSString *)host
|
||||
ip:(NSString *)ip;
|
||||
|
||||
- (QNNetworkStatus *)getNetworkStatus:(NSString *)type;
|
||||
|
||||
- (void)updateNetworkStatus:(NSString *)type
|
||||
speed:(int)speed;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
93
Pods/Qiniu/QiniuSDK/Http/NetworkStatus/QNNetworkStatusManager.m
generated
Normal file
93
Pods/Qiniu/QiniuSDK/Http/NetworkStatus/QNNetworkStatusManager.m
generated
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// QNNetworkStatusManager.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/11/17.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNUtils.h"
|
||||
#import "QNCache.h"
|
||||
#import "QNAsyncRun.h"
|
||||
#import "QNFileRecorder.h"
|
||||
#import "QNRecorderDelegate.h"
|
||||
#import "QNNetworkStatusManager.h"
|
||||
|
||||
@interface QNNetworkStatus()<QNCacheObject>
|
||||
@property(nonatomic, assign)int speed;
|
||||
@end
|
||||
@implementation QNNetworkStatus
|
||||
- (instancetype)init{
|
||||
if (self = [super init]) {
|
||||
_speed = 200;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nonnull id<QNCacheObject>)initWithDictionary:(nullable NSDictionary *)dictionary {
|
||||
QNNetworkStatus *status = [[QNNetworkStatus alloc] init];
|
||||
status.speed = [dictionary[@"speed"] intValue];
|
||||
return status;
|
||||
}
|
||||
|
||||
- (NSDictionary *)toDictionary{
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[dictionary setObject:@(self.speed) forKey:@"speed"];
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
+ (QNNetworkStatus *)statusFromDictionary:(NSDictionary *)dictionary{
|
||||
QNNetworkStatus *status = [[QNNetworkStatus alloc] init];
|
||||
status.speed = [dictionary[@"speed"] intValue];
|
||||
return status;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@interface QNNetworkStatusManager()
|
||||
|
||||
@property(nonatomic, strong)QNCache *cache;
|
||||
|
||||
@end
|
||||
@implementation QNNetworkStatusManager
|
||||
|
||||
+ (instancetype)sharedInstance{
|
||||
static QNNetworkStatusManager *manager = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
manager = [[QNNetworkStatusManager alloc] init];
|
||||
[manager initData];
|
||||
});
|
||||
return manager;
|
||||
}
|
||||
|
||||
- (void)initData{
|
||||
QNCacheOption *option = [[QNCacheOption alloc] init];
|
||||
option.version = @"v1.0.2";
|
||||
option.flushCount = 10;
|
||||
self.cache = [QNCache cache:[QNNetworkStatus class] option:option];
|
||||
}
|
||||
|
||||
+ (NSString *)getNetworkStatusType:(NSString *)host
|
||||
ip:(NSString *)ip {
|
||||
return [QNUtils getIpType:ip host:host];
|
||||
}
|
||||
|
||||
- (QNNetworkStatus *)getNetworkStatus:(NSString *)type{
|
||||
if (type == nil || type.length == 0) {
|
||||
return nil;
|
||||
}
|
||||
return [self.cache cacheForKey:type];
|
||||
}
|
||||
|
||||
- (void)updateNetworkStatus:(NSString *)type speed:(int)speed{
|
||||
if (type == nil || type.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
QNNetworkStatus *status = [[QNNetworkStatus alloc] init];
|
||||
status.speed = speed;
|
||||
[self.cache cache:status forKey:type atomically:false];
|
||||
}
|
||||
|
||||
@end
|
||||
24
Pods/Qiniu/QiniuSDK/Http/NetworkStatus/QNUploadServerNetworkStatus.h
generated
Normal file
24
Pods/Qiniu/QiniuSDK/Http/NetworkStatus/QNUploadServerNetworkStatus.h
generated
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// QNUploadServerNetworkStatus.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/11/17.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "QNUploadServer.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QNUploadServerNetworkStatus : NSObject
|
||||
|
||||
+ (QNUploadServer *)getBetterNetworkServer:(QNUploadServer *)serverA
|
||||
serverB:(QNUploadServer *)serverB;
|
||||
|
||||
+ (BOOL)isServerNetworkBetter:(QNUploadServer *)serverA
|
||||
thanServerB:(QNUploadServer *)serverB;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
40
Pods/Qiniu/QiniuSDK/Http/NetworkStatus/QNUploadServerNetworkStatus.m
generated
Normal file
40
Pods/Qiniu/QiniuSDK/Http/NetworkStatus/QNUploadServerNetworkStatus.m
generated
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// QNUploadServerNetworkStatus.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/11/17.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNUtils.h"
|
||||
#import "QNNetworkStatusManager.h"
|
||||
#import "QNUploadServerNetworkStatus.h"
|
||||
|
||||
@implementation QNUploadServerNetworkStatus
|
||||
|
||||
+ (QNUploadServer *)getBetterNetworkServer:(QNUploadServer *)serverA serverB:(QNUploadServer *)serverB {
|
||||
return [self isServerNetworkBetter:serverA thanServerB:serverB] ? serverA : serverB;
|
||||
}
|
||||
|
||||
+ (BOOL)isServerNetworkBetter:(QNUploadServer *)serverA thanServerB:(QNUploadServer *)serverB {
|
||||
if (serverA == nil) {
|
||||
return NO;
|
||||
} else if (serverB == nil) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
NSString *serverTypeA = [QNNetworkStatusManager getNetworkStatusType:serverA.host ip:serverA.ip];
|
||||
NSString *serverTypeB = [QNNetworkStatusManager getNetworkStatusType:serverB.host ip:serverB.ip];
|
||||
if (serverTypeA == nil) {
|
||||
return NO;
|
||||
} else if (serverTypeB == nil) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
QNNetworkStatus *serverStatusA = [kQNNetworkStatusManager getNetworkStatus:serverTypeA];
|
||||
QNNetworkStatus *serverStatusB = [kQNNetworkStatusManager getNetworkStatus:serverTypeB];
|
||||
|
||||
return serverStatusB.speed < serverStatusA.speed;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user