static void _EnsureFlags()

in Source/NSURLSessionConfiguration+TNLAdditions.m [23:86]


static void _EnsureFlags()
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{

        memset(&sFlags, 0, sizeof(sFlags)); // clear the flags before we set them

        /// URLSessionCanUseTaskTransactionMetrics

        // task metrics added as an API in iOS 10
        {
            if (tnl_available_ios_11) {

                // The crashers of iOS 10 continue into iOS 11 betas.
                // The crash was fixed in iOS 11.0.0 GM.
                // Since we cannot differentiate GM vs earlier beta, there can be crashing...
                // ...but those betas are old enough now to not need special consideration.

                // Consider fixed on iOS 11+
                sFlags.URLSessionCanUseTaskTransactionMetrics = YES;

            } else {
                // task metrics exist but have crashes on iOS 10.X
                // iOS 10.0.X and iOS 10.1.X have a crashing bug that crashes 1 million times a day
                // iOS 10.2+ has a different crasher, 5 thousand per day
            }
        }

        /// URLSessionSupportsDecodingBrotliContentEncoding

        // Brotli support requires 2 things:
        // - Running OS version of iOS 11 (or equivalent platform version) or greater
        //   AND
        // - Target SDK at compile time of iOS 11 (or equivalent platform version) or greater

#if TARGET_SDK_SUPPORTS_BROTLI
        if (tnl_available_ios_11) {
            sFlags.URLSessionSupportsDecodingBrotliContentEncoding = YES;
        }
#endif

        /// URLSessionCanUseWaitsForConnectivity

        if (tnl_available_ios_11) {

            // added iOS 11
            sFlags.URLSessionCanUseWaitsForConnectivity = YES;

            if (tnl_available_ios_13) {

                // regressed iOS 13.0
                sFlags.URLSessionCanUseWaitsForConnectivity = NO;

                if (@available(iOS 13.1, tvOS 13.1, macOS 10.15.0, watchOS 6.1, *)) {

                    // fixed iOS 13.1 beta 1
                    // fixed macOS 10.15.0 beta 7
                    sFlags.URLSessionCanUseWaitsForConnectivity = YES;

                }
            }
        }
    });
}