Skip to content

Commit 8033487

Browse files
Add interceptor imports and application support for iOS
Agent-Logs-Url: https://github.com/nativescript-community/https/sessions/b7e39983-090a-48a9-b8d2-1f08682e72e0 Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
1 parent 7ddbc60 commit 8033487

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/https/request.ios.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { File, ImageSource, Utils } from '@nativescript/core';
22
import { CacheOptions, HttpsFormDataParam, HttpsRequest, HttpsRequestOptions, HttpsResponse, HttpsSSLPinningOptions, HttpsResponseLegacy as IHttpsResponseLegacy } from '.';
3-
import { getFilenameFromUrl, parseJSON } from './request.common';
3+
import { getFilenameFromUrl, interceptors, networkInterceptors, parseJSON } from './request.common';
44
export { addInterceptor, addNetworkInterceptor } from './request.common';
55

66
// Error keys used by the Swift wrapper to maintain compatibility with AFNetworking
@@ -43,6 +43,27 @@ policies.def.validatesDomainName = false;
4343
const configuration = NSURLSessionConfiguration.defaultSessionConfiguration;
4444
let manager = AlamofireWrapper.alloc().initWithConfiguration(configuration);
4545

46+
// Note: iOS interceptors must be native Alamofire RequestInterceptor or EventMonitor objects
47+
// They cannot be JavaScript functions like Android OkHttp interceptors
48+
// To use interceptors on iOS, you need to create native Swift wrapper classes
49+
50+
// Apply interceptors from common if they are Alamofire-compatible objects
51+
function applyInterceptors() {
52+
interceptors.forEach((interceptor) => {
53+
if (interceptor && typeof interceptor === 'object' && 'adapt' in interceptor) {
54+
manager.addInterceptor(interceptor);
55+
}
56+
});
57+
networkInterceptors.forEach((monitor) => {
58+
if (monitor && typeof monitor === 'object') {
59+
manager.addEventMonitor(monitor);
60+
}
61+
});
62+
}
63+
64+
// Apply any pre-existing interceptors
65+
applyInterceptors();
66+
4667
export function enableSSLPinning(options: HttpsSSLPinningOptions) {
4768
const url = NSURL.URLWithString(options.host);
4869
manager = AlamofireWrapper.alloc().initWithConfigurationBaseURL(configuration, url);

0 commit comments

Comments
 (0)