@@ -26,6 +26,7 @@ import Foundation
26
26
import UIKit
27
27
28
28
public typealias CLDCompletionHandler = ( _ responseImage: UIImage ? , _ error: NSError ? ) -> ( )
29
+ public typealias CLDAssetCompletionHandler = ( _ responseAsset: Data ? , _ error: NSError ? ) -> ( )
29
30
public typealias CLDUploadCompletionHandler = ( _ response: CLDUploadResult ? , _ error: NSError ? ) -> ( )
30
31
31
32
@objcMembers open class CLDCloudinary : NSObject {
@@ -40,6 +41,10 @@ public typealias CLDUploadCompletionHandler = (_ response: CLDUploadResult?, _ e
40
41
*/
41
42
fileprivate var networkCoordinator : CLDNetworkCoordinator
42
43
44
+ /**
45
+ The network download coordinator coordinates between the SDK's API level classes to its network adapter layer.
46
+ */
47
+ fileprivate var downloadCoordinator : CLDDownloadCoordinator
43
48
44
49
// MARK: - SDK Configurations
45
50
@@ -65,23 +70,23 @@ public typealias CLDUploadCompletionHandler = (_ response: CLDUploadResult?, _ e
65
70
*/
66
71
open var cachePolicy : CLDImageCachePolicy {
67
72
get {
68
- return CLDImageCache . defaultImageCache . cachePolicy
73
+ return downloadCoordinator . imageCache . cachePolicy
69
74
}
70
75
set {
71
- CLDImageCache . defaultImageCache . cachePolicy = newValue
76
+ downloadCoordinator . imageCache . cachePolicy = newValue
72
77
}
73
78
}
74
79
75
80
/**
76
81
Sets Cloudinary SDK's image cache maximum disk capacity.
77
- default is 150 MB.
82
+ default is 150 MB.
78
83
*/
79
84
open var cacheMaxDiskCapacity : UInt64 {
80
85
get {
81
- return CLDImageCache . defaultImageCache . maxDiskCapacity
86
+ return downloadCoordinator . imageCache . maxDiskCapacity
82
87
}
83
88
set {
84
- CLDImageCache . defaultImageCache . maxDiskCapacity = newValue
89
+ downloadCoordinator . imageCache . maxDiskCapacity = newValue
85
90
}
86
91
}
87
92
@@ -91,21 +96,47 @@ public typealias CLDUploadCompletionHandler = (_ response: CLDUploadResult?, _ e
91
96
*/
92
97
open var cacheMaxMemoryTotalCost : Int {
93
98
get {
94
- return CLDImageCache . defaultImageCache. maxMemoryTotalCost
99
+ return downloadCoordinator. imageCache. maxMemoryTotalCost
100
+ }
101
+ set {
102
+ downloadCoordinator. imageCache. maxMemoryTotalCost = newValue
103
+ }
104
+ }
105
+
106
+ /**
107
+ Sets Cloudinary SDK's asset cache maximum disk capacity.
108
+ default is 150 MB.
109
+ */
110
+ open var cacheAssetMaxDiskCapacity : Int {
111
+ get {
112
+ return downloadCoordinator. urlCache. diskCapacity
95
113
}
96
114
set {
97
- CLDImageCache . defaultImageCache . maxMemoryTotalCost = newValue
115
+ downloadCoordinator . urlCache . updateDiskCapacity ( newValue)
98
116
}
99
117
}
100
118
119
+ /**
120
+ Sets Cloudinary SDK's asset cache maximum memory total cost.
121
+ default is 30 MB.
122
+ */
123
+ open var cacheAssetMaxMemoryTotalCost : Int {
124
+ get {
125
+ return downloadCoordinator. urlCache. memoryCapacity
126
+ }
127
+ set {
128
+ downloadCoordinator. urlCache. updateMemoryCapacity ( newValue)
129
+ }
130
+ }
131
+
101
132
/**
102
133
Removes an image from the downloaded images cache, both disk and memory.
103
134
104
135
- parameter key: The full url of the image to remove.
105
136
106
137
*/
107
138
open func removeFromCache( key: String ) {
108
- CLDImageCache . defaultImageCache . removeCacheImageForKey ( key)
139
+ downloadCoordinator . imageCache . removeCacheImageForKey ( key)
109
140
}
110
141
111
142
// MARK: - Init
@@ -118,7 +149,25 @@ public typealias CLDUploadCompletionHandler = (_ response: CLDUploadResult?, _ e
118
149
119
150
- returns: The new `CLDCloudinary` instance.
120
151
*/
121
- public init ( configuration: CLDConfiguration , networkAdapter: CLDNetworkAdapter ? = nil , sessionConfiguration: URLSessionConfiguration ? = nil ) {
152
+ public convenience init ( configuration: CLDConfiguration , networkAdapter: CLDNetworkAdapter ? = nil , sessionConfiguration: URLSessionConfiguration ? = nil ) {
153
+
154
+ self . init ( configuration: configuration, networkAdapter: networkAdapter, downloadAdapter: nil , sessionConfiguration: sessionConfiguration, downloadSessionConfiguration: nil )
155
+ }
156
+
157
+ /**
158
+ Initializes the `CLDCloudinary` instance with the specified configuration and network adapter.
159
+
160
+ - parameter configuration: The configuration used by this CLDCloudinary instance.
161
+ - parameter networkAdapter: A network adapter that implements `CLDNetworkAdapter`.
162
+ - parameter downloadAdapter: A download adapter that implements `CLDNetworkAdapter`.
163
+ - parameter sessionConfiguration: A session configuration that implements `URLSessionConfiguration`.
164
+ - parameter downloadSessionConfiguration: A download session configuration that implements `URLSessionConfiguration`.
165
+ CLDNetworkDelegate() by default.
166
+
167
+ - returns: The new `CLDCloudinary` instance.
168
+ */
169
+ public init ( configuration: CLDConfiguration , networkAdapter: CLDNetworkAdapter ? = nil , downloadAdapter: CLDNetworkAdapter ? = nil , sessionConfiguration: URLSessionConfiguration ? = nil , downloadSessionConfiguration: URLSessionConfiguration ? = nil ) {
170
+
122
171
config = configuration
123
172
if let customNetworkAdapter = networkAdapter {
124
173
networkCoordinator = CLDNetworkCoordinator ( configuration: config, networkAdapter: customNetworkAdapter)
@@ -129,6 +178,17 @@ public typealias CLDUploadCompletionHandler = (_ response: CLDUploadResult?, _ e
129
178
networkCoordinator = CLDNetworkCoordinator ( configuration: config)
130
179
}
131
180
}
181
+
182
+ if let customDownloadAdapter = downloadAdapter {
183
+ downloadCoordinator = CLDDownloadCoordinator ( configuration: config, networkAdapter: customDownloadAdapter)
184
+ } else {
185
+ if let downloadSessionConfiguration = downloadSessionConfiguration {
186
+ downloadCoordinator = CLDDownloadCoordinator ( configuration: config, sessionConfiguration: downloadSessionConfiguration)
187
+ } else {
188
+ downloadCoordinator = CLDDownloadCoordinator ( configuration: config)
189
+ }
190
+ }
191
+
132
192
super. init ( )
133
193
}
134
194
@@ -158,7 +218,7 @@ public typealias CLDUploadCompletionHandler = (_ response: CLDUploadResult?, _ e
158
218
- returns: A new `CLDDownloader` instance.
159
219
*/
160
220
open func createDownloader( ) -> CLDDownloader {
161
- return CLDDownloader ( networkCoordinator : networkCoordinator )
221
+ return CLDDownloader ( downloadCoordinator : downloadCoordinator )
162
222
}
163
223
164
224
/**
0 commit comments