1

I want to implement my API's hitting mechanism to use HTTP2/3 using QUIC as their transport layer, which provides benefits for reduce latency and improved multiplexing.

I am using Cronet in android native app using java. Same i want to use in my iOS native app using Swift.

Cronet's usage in swift app is not explained anywhere in web.

I am using this library Cronet.framework

and its implementation i found is this.

Add in Podfile and do pod install in terminal.

pod 'Cronet'

then in AppDelegate

import Cronet

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        setupCronet()
        return true
    }

    private func setupCronet() {
        Cronet.setHttp2Enabled(true)
        Cronet.setQuicEnabled(true)
        Cronet.setBrotliEnabled(true)
        Cronet.setHttpCacheType(.memory)
        Cronet.start()
        Cronet.registerHttpProtocolHandler()
    }
}

But there is no other implementation in project to call like in Android we call CronetEngine and then to call the api's.

Question is:

  • Do i need to use URLSession for network calls as usual and it will use cronet. (I don't think so)

  • The other thought is Apple's URLSession in latest version of iOS supports Http2/3 using QUIC itself(precondition, the HTTP server supports QUIC protocol) and we do not need to use Cronet like we did in android?????

1

1 Answer 1

0

+1 to the comment advising you to minimize the use of third-party networking libraries.

But to answer the question, my vague recollection is that Cronet installs itself as an NSURLProtocol, so presumably you would need to make sure Cronet is part of the set of protocol classes on your session.

A quick search found this:

https://medium.com/the-react-native-log/using-cronet-in-your-mobile-app-7dda3a89c132

which agrees with that recollection, and provides a useful snippet:

#include <Cronet/Cronet.h>
...
[Cronet setHttp2Enabled:YES];
[Cronet setQuicEnabled:YES];
[Cronet setBrotliEnabled:YES];
[Cronet setHttpCacheType:CRNHttpCacheTypeDisk];
[Cronet addQuicHint:@"yourhostname.tld" port:443 altPort:443];
[Cronet start];
[Cronet registerHttpProtocolHandler];

Note, however, that AFAIK, the registerHttpProtocolHandler method in that snippet registers Cronet only for the shared session. For all other sessions, you'll have to manually add the NSURLProtocol class to the array of protocols registered for that session.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.