Depreacted: This package was relevant when iOS didn't support QUIC/HTTP3. iOS15 onwards has native support.
Cronet is the Chromium network stack made available to iOS apps as a library.
Cronet takes advantage of multiple technologies that reduce the latency and increase the throughput of the network requests that your app needs to work.
This is the same networking stack that is used in the Chrome browser by over a billion people. Cronet has support for both Android and iOS.
This package makes it easy to use Cronet in your iOS apps.
Note: You will have to disable bitcode on your target.
-
Protocol support
Cronet natively supports the HTTP, HTTP/2, and QUIC protocols.
-
Request prioritization
The library allows you to set a priority tag for the requests. The server can use the priority tag to determine the order in which to handle the requests.
-
Resource caching
Cronet can use an in-memory or disk cache to store resources retrieved in network requests. Subsequent requests are served from the cache automatically.
-
Asynchronous requests
Network requests issued using the Cronet Library are asynchronous by default. Your worker threads aren't blocked while waiting for the request to come back.
-
Data compression
Cronet supports data compression using the Brotli Compressed Data Format.
You may be wondering, if Cronet is a chromium libary, what is this repo about?
That is right, Cronet is a chromium library and this repo doesn't add or modify any chromium code. For that fact this repo doesn't even have any code. This repo is about making Cronet easier to use in your iOS app if you are not a google employee.
As some one of HN succiently said:
Chromium is a fairly typical google project where the recommended first step to building it is to become a google employee but some alternative workarounds are also available if that's not practical.
More precisely this repo:
- Fetches unofficial cronet build artificats that chromium publishes.
- Merge the iphoneos and iphonesimulator frameworks together using
lipo
for both static and dynamic builds - Publishes a github release with the static, dymanic and dysm archives attached to the release on github
- Publishes the static version of the module to cocoapods under Cronet
- Make sure bitcode is disabled on the target you want to link
Cronet
with. - Link
Cronet.framework
into your iOS app's workspace/project either usingcocoapods
or manually linking the framework.
- Add
pod 'Cronet'
under your desired target in yourPodfile
: - Run
pod install
- Download the appropriate archive that you want to use from the latest release
- Extarct the archive and copy the
Cronet.framewrok
folder into your project by dragging the folder into your project in Xcode. Make sure to select Copy items if needed in the dialog that pops up - In your
Target
->Build Phase
->Link Binary With Libraries
addSystemConfiguration.framework
- In your
Target
->Build Settings
->Other Linker Flags
add-lc++
Initialize cronet somewhere in your app's start flow. For example, in:
- (BOOL)application:... didFinishLaunchingWithOptions:...
Add:
[Cronet setHttp2Enabled:YES];
[Cronet setQuicEnabled:YES];
[Cronet setBrotliEnabled:YES];
[Cronet start];
[Cronet registerHttpProtocolHandler];
For a complete list of initilization options see Cronet.h
- Cronet library is not available in a bitcode enabled version. So you must disable bitcode in your target to use it.
- Some
NSURLSession*Delegate
callback's don't work when cronet is registered as a protocol handler in that session. - Dsym is only available for dynamic framework.
See the LICENSE file for more info.