cronet-ios.md
September 2, 2025 · View on GitHub
Cronet C API integration (iOS)
High-level steps
- Add Cronet framework to the iOS project (via CocoaPods or manual integration). Cronet for iOS ships as a framework with C and Objective‑C APIs.
- Expose headers to Swift by adding a bridging header for C if needed, or use the C API from a small Objective‑C++ (*.mm) wrapper.
- Initialize a shared engine (similar to Android) and hold it for the app lifetime.
- Implement
request(_ req: NitroRequest) async throws -> NitroResponseinNitroFetch.swiftby calling into the C/ObjC++ wrapper.
Linking
- In the Podspec, add the Cronet pod or vendored framework, e.g.:
s.vendored_frameworks = 'path/to/Cronet.framework'
Engine + request wrapper (ObjC++)
// CronetBridge.h/.mm
#import <cronet/cronet_c.h>
bool CronetInit(void);
void CronetShutdown(void);
bool CronetRequest(const NitroRequest* req, NitroResponse* out);
Swift glue
final class NitroFetch: HybridNitroFetchSpec {
public func request(req: NitroRequest) async throws -> NitroResponse {
// Call CronetRequest, translate errors into thrown Swift errors
}
}
Notes
- Use async/await in Swift signatures generated by Nitro for Promise returns.
- For streaming, add request handle ids and expose chunk events; use Nitro event emitters.
- Ensure ATS (App Transport Security) allows your test endpoints or use https.