-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHYNetworkConfig.m
More file actions
84 lines (70 loc) · 1.78 KB
/
HYNetworkConfig.m
File metadata and controls
84 lines (70 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// HYNetworkConfig.m
// YTKNetworkDemo
//
// Created by zheng on 2017/8/4.
// Copyright © 2017年 yuantiku.com. All rights reserved.
//
#import "HYNetworkConfig.h"
#import "HYBaseRequest.h"
#if __has_include(<AFNetworking/AFNetworking.h>)
#import <AFNetworking/AFNetworking.h>
#else
#import "AFNetworking.h"
#endif
@implementation HYNetworkConfig
{
NSMutableArray<id<HYUrlFilterProtocol>> *_urlFilters;
NSMutableArray<id<HYCacheDirPathFilterProtocol>> *_cacheDirPathFilters;
}
+ (HYNetworkConfig *)sharedConfig
{
static id sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (instancetype)init
{
self = [super init];
if (self)
{
_baseUrl = @"";
_cdnUrl = @"";
_urlFilters = [NSMutableArray array];
_cacheDirPathFilters = [NSMutableArray array];
_securityPolicy = [AFSecurityPolicy defaultPolicy];
_debugLogEnabled = NO;
}
return self;
}
- (void)addUrlFilter:(id<HYUrlFilterProtocol>)filter
{
[_urlFilters addObject:filter];
}
- (void)clearUrlFilter {
[_urlFilters removeAllObjects];
}
- (void)addCacheDirPathFilter:(id<HYCacheDirPathFilterProtocol>)filter
{
[_cacheDirPathFilters addObject:filter];
}
- (void)clearCacheDirPathFilter {
[_cacheDirPathFilters removeAllObjects];
}
- (NSArray<id<HYUrlFilterProtocol>> *)urlFilters
{
return [_urlFilters copy];
}
- (NSArray<id<HYCacheDirPathFilterProtocol>> *)cacheDirPathFilters
{
return [_cacheDirPathFilters copy];
}
#pragma mark - NSObject
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p>{ baseURL: %@ } { cdnURL: %@ }", NSStringFromClass([self class]), self, self.baseUrl, self.cdnUrl];
}
@end