@capacitor/ios 5.7.5 → 5.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -107,7 +107,7 @@ internal class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
func webView(_ webView: WKWebView, stop urlSchemeTask: WKURLSchemeTask) {
|
|
110
|
-
|
|
110
|
+
urlSchemeTask.stopped = true
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
func mimeTypeForExtension(pathExtension: String) -> String {
|
|
@@ -155,43 +155,46 @@ internal class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
155
155
|
|
|
156
156
|
let urlSession = URLSession.shared
|
|
157
157
|
let task = urlSession.dataTask(with: urlRequest) { (data, response, error) in
|
|
158
|
-
|
|
159
|
-
urlSchemeTask.
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
DispatchQueue.main.async {
|
|
159
|
+
guard !urlSchemeTask.stopped else { return }
|
|
160
|
+
if let error = error {
|
|
161
|
+
urlSchemeTask.didFailWithError(error)
|
|
162
|
+
return
|
|
163
|
+
}
|
|
162
164
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
165
|
+
if let response = response as? HTTPURLResponse {
|
|
166
|
+
let existingHeaders = response.allHeaderFields
|
|
167
|
+
var newHeaders: [AnyHashable: Any] = [:]
|
|
166
168
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
// if using live reload, then set CORS headers
|
|
170
|
+
if self.isUsingLiveReload(url) {
|
|
171
|
+
newHeaders = [
|
|
172
|
+
"Access-Control-Allow-Origin": self.serverUrl?.absoluteString ?? "",
|
|
173
|
+
"Access-Control-Allow-Methods": "GET, HEAD, OPTIONS, TRACE"
|
|
174
|
+
]
|
|
175
|
+
}
|
|
174
176
|
|
|
175
|
-
|
|
177
|
+
if let mergedHeaders = existingHeaders.merging(newHeaders, uniquingKeysWith: { (_, newHeaders) in newHeaders }) as? [String: String] {
|
|
176
178
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
179
|
+
if let responseUrl = response.url {
|
|
180
|
+
if let modifiedResponse = HTTPURLResponse(
|
|
181
|
+
url: responseUrl,
|
|
182
|
+
statusCode: response.statusCode,
|
|
183
|
+
httpVersion: nil,
|
|
184
|
+
headerFields: mergedHeaders
|
|
185
|
+
) {
|
|
186
|
+
urlSchemeTask.didReceive(modifiedResponse)
|
|
187
|
+
}
|
|
185
188
|
}
|
|
186
|
-
}
|
|
187
189
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
if let data = data {
|
|
191
|
+
urlSchemeTask.didReceive(data)
|
|
192
|
+
}
|
|
190
193
|
}
|
|
191
194
|
}
|
|
195
|
+
urlSchemeTask.didFinish()
|
|
196
|
+
return
|
|
192
197
|
}
|
|
193
|
-
urlSchemeTask.didFinish()
|
|
194
|
-
return
|
|
195
198
|
}
|
|
196
199
|
|
|
197
200
|
task.resume()
|
|
@@ -546,3 +549,16 @@ internal class WebViewAssetHandler: NSObject, WKURLSchemeHandler {
|
|
|
546
549
|
"zip": "application/x-zip-compressed"
|
|
547
550
|
]
|
|
548
551
|
}
|
|
552
|
+
|
|
553
|
+
private var stoppedKey = malloc(1)
|
|
554
|
+
|
|
555
|
+
private extension WKURLSchemeTask {
|
|
556
|
+
var stopped: Bool {
|
|
557
|
+
get {
|
|
558
|
+
return objc_getAssociatedObject(self, &stoppedKey) as? Bool ?? false
|
|
559
|
+
}
|
|
560
|
+
set {
|
|
561
|
+
objc_setAssociatedObject(self, &stoppedKey, newValue, .OBJC_ASSOCIATION_ASSIGN)
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
@@ -65,22 +65,29 @@ var nativeBridge = (function (exports) {
|
|
|
65
65
|
return newFormData;
|
|
66
66
|
};
|
|
67
67
|
const convertBody = async (body, contentType) => {
|
|
68
|
-
if (body instanceof ReadableStream) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
if (body instanceof ReadableStream || body instanceof Uint8Array) {
|
|
69
|
+
let encodedData;
|
|
70
|
+
if (body instanceof ReadableStream) {
|
|
71
|
+
const reader = body.getReader();
|
|
72
|
+
const chunks = [];
|
|
73
|
+
while (true) {
|
|
74
|
+
const { done, value } = await reader.read();
|
|
75
|
+
if (done)
|
|
76
|
+
break;
|
|
77
|
+
chunks.push(value);
|
|
78
|
+
}
|
|
79
|
+
const concatenated = new Uint8Array(chunks.reduce((acc, chunk) => acc + chunk.length, 0));
|
|
80
|
+
let position = 0;
|
|
81
|
+
for (const chunk of chunks) {
|
|
82
|
+
concatenated.set(chunk, position);
|
|
83
|
+
position += chunk.length;
|
|
84
|
+
}
|
|
85
|
+
encodedData = concatenated;
|
|
76
86
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
for (const chunk of chunks) {
|
|
80
|
-
concatenated.set(chunk, position);
|
|
81
|
-
position += chunk.length;
|
|
87
|
+
else {
|
|
88
|
+
encodedData = body;
|
|
82
89
|
}
|
|
83
|
-
let data = new TextDecoder().decode(
|
|
90
|
+
let data = new TextDecoder().decode(encodedData);
|
|
84
91
|
let type;
|
|
85
92
|
if (contentType === 'application/json') {
|
|
86
93
|
try {
|
|
@@ -569,20 +576,7 @@ var nativeBridge = (function (exports) {
|
|
|
569
576
|
value: xhr.method,
|
|
570
577
|
writable: true,
|
|
571
578
|
},
|
|
572
|
-
readyState: {
|
|
573
|
-
get: function () {
|
|
574
|
-
var _a;
|
|
575
|
-
return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0;
|
|
576
|
-
},
|
|
577
|
-
set: function (val) {
|
|
578
|
-
this._readyState = val;
|
|
579
|
-
setTimeout(() => {
|
|
580
|
-
this.dispatchEvent(new Event('readystatechange'));
|
|
581
|
-
});
|
|
582
|
-
},
|
|
583
|
-
},
|
|
584
579
|
});
|
|
585
|
-
xhr.readyState = 0;
|
|
586
580
|
const prototype = win.CapacitorWebXMLHttpRequest.prototype;
|
|
587
581
|
const isProgressEventAvailable = () => typeof ProgressEvent !== 'undefined' &&
|
|
588
582
|
ProgressEvent.prototype instanceof Event;
|
|
@@ -612,6 +606,20 @@ var nativeBridge = (function (exports) {
|
|
|
612
606
|
this._url = createProxyUrl(this._url, win);
|
|
613
607
|
return win.CapacitorWebXMLHttpRequest.open.call(this, method, this._url);
|
|
614
608
|
}
|
|
609
|
+
Object.defineProperties(this, {
|
|
610
|
+
readyState: {
|
|
611
|
+
get: function () {
|
|
612
|
+
var _a;
|
|
613
|
+
return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0;
|
|
614
|
+
},
|
|
615
|
+
set: function (val) {
|
|
616
|
+
this._readyState = val;
|
|
617
|
+
setTimeout(() => {
|
|
618
|
+
this.dispatchEvent(new Event('readystatechange'));
|
|
619
|
+
});
|
|
620
|
+
},
|
|
621
|
+
},
|
|
622
|
+
});
|
|
615
623
|
setTimeout(() => {
|
|
616
624
|
this.dispatchEvent(new Event('loadstart'));
|
|
617
625
|
});
|
package/package.json
CHANGED