|
1 | 1 | import { File, ImageSource, Utils } from '@nativescript/core'; |
2 | 2 | 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'; |
4 | 4 | export { addInterceptor, addNetworkInterceptor } from './request.common'; |
5 | 5 |
|
6 | 6 | // Error keys used by the Swift wrapper to maintain compatibility with AFNetworking |
@@ -43,6 +43,27 @@ policies.def.validatesDomainName = false; |
43 | 43 | const configuration = NSURLSessionConfiguration.defaultSessionConfiguration; |
44 | 44 | let manager = AlamofireWrapper.alloc().initWithConfiguration(configuration); |
45 | 45 |
|
| 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 | + |
46 | 67 | export function enableSSLPinning(options: HttpsSSLPinningOptions) { |
47 | 68 | const url = NSURL.URLWithString(options.host); |
48 | 69 | manager = AlamofireWrapper.alloc().initWithConfigurationBaseURL(configuration, url); |
|
0 commit comments