Advances in Networking, Part 1
Show Apple's description.
Keep up with new and evolving networking protocols and standards by leveraging the modern networking frameworks on all Apple platforms and following best practices for efficiency and performance. In this session, learn about Low Data Mode, Combine in URLSession, WebSocket, and improvements to network mobility.
Low data mode
New User preference to minimize data usage:
- Explicit signal to reduce network data use
- Per Wi-Fi and Cellular network
- Discretionary tasks deferred
- Background App Refresh disabled
Application adoption suggestions:
- Reduce Image quality
- Reduce pre-fetching
- Sync less often
- Mark Background tasks as discretionary (will run when iOS says so)
- Disable auto-play
- Do not block user-initiated work
- Try large prefetch with
allowsConstrainedNetworkAccess = false, which allow the
URLSessionto run even on low data mode.
- On failure with
error.networkUnavailableReason == .constrainedtry Low Data Mode alternative If you get a failure and the error has a network unavailable reason of constrained, that indicates the operation failed because you're in Low Data Mode and the right thing to do there is to turn around and perform your Low Data Mode operation.
- Set prohibitConstrainedPaths on NWParameters
- Check isConstrained on NWPath
- Handle path updates
Combine in URLSession
What is Combine?
- Combine processes values over time.
- It consists of publishers, operators, and subscribers.
- The chain is driven by the request sent from the subscriber.
- In response to the request, publisher sends value down the chain.
URLSession publisher, similar to
- lets us write code concise, linear, and less error-prone. less duplication
- Cells can be subscribers, and on reuse we can cancel the previous tasks.
- Cool demo at 20-25min in.
URLSessionWebSocketTask, a new API in the foundation framework.
Wifi and mobile data switch got smarter once again.
- Wi-Fi Assist was applied to hight-level APIs like Network.Framework and URLSession in iOS 13. Whenever the wifi connection is bad or loss. it will switch to connect cellular.
- Multipath Transports
allowsExpensiveNetworkAccess = false