@ WWDC 19
์ค์ ์์ low data mode๋ฅผ ์ค์ ํ ์ ์๋ค. ์ด ์ต์ ์ ์ผฐ์ ๋ ์ฑ์ด ์ด๋ป๊ฒ ์๋ํ ์ง ๊ฐ๋ฐํ๋ฉด์ ์ค์ ํด ์ค ์ ์๋ค.
- User preference to minimize data usage
- Explicit signal to reduce network data use
- Peer Wi-Fi and Cellular network
- System plicy
- Discretionary tasks deferred
- Background App Refresh disabled
๋ด ์ฑ์ ์ ์ฉํ ๋!, ์ด ์ต์ ์ด ์ผ์ ธ ์๋ค๋ฉด
- Reduce image quality
- Reduce pre-fetching
- Synchronize less often
- Mark tasks discretionary
- Disble auto-play
- Do not block user-initiated work
- URLSession
- Try large/prefetch with
allowsConstrainedNetworkAccess = false
- On failure with
error.networkUnavailableReason == .constrained
try Low Data Mode alternative
- Try large/prefetch with
- Network framework
- Set
prohibitConstrainedPaths
onNWParameteers
- Handle path updatees
- Set
- Constrained - Low Data Mode
- Expensive - Cellular and Personal Hotspot
- URLSession
allowsExpensiveNetworkAccess
- Network.framework
- Set
prohibitExpensivePaths
onNWParameters
- Check
isExpensive
onNWPath
- Set
13๋ถํฐ ๋์จ Combine์ ์ด๋ป๊ฒ URLSession๊ณผ ํจ๊ป ์ฐ๋์ง ๋ฐ๋ชจ์ ํจ๊ป ์ค๋ช . Combine์ ๋ํด ์ข ์๊ณ ๋ด์ผ ์ดํด๊ฐ ๊ฐ๋ฅํ์ง๋ง ๋๊ฐ Rx ์ด์ง ๋ง๋ดค๋ ์ ๋๋ก ์ดํด ๊ฐ๋ฅ
- Streamline networking code with Combine
- Support retry
- Use low retry count
- Only idempotent request
- Best practices for Low Data Mode
// Generalized Publisher for Adaptive URL Loading
func adaptiveLoader(regularURL: URL, lowDataURL: URL) -> AnyPPublisher<Data, Error> {
var request = URLRequest(url: regularURL)
request.allowsConstrainedNetworkAccess = false
return URLSession.shared.dataTaskPublisher(for: request)
.tryCatch { error -> URLSession.DataTaskPublisher in
guard error.networkUnavailableReason == .constrained else {
throw error
}
return URLSession.shared.dataTaskPublisher(for: lowDataURL)
}
.tryMap { data, response -> Data in
guard let httpResponse = response as? HTTPURLResponse,
httpResponse.statusCode == 200 else {
throw MyNetworkingError.invalidServerResponse
}
return data
}
.eraseToAnyPublisher()
}
์น์์ผ ์ด์ฉํ๋ฉด ์๋ฐฉํฅ ํต์ ์ด ๊ฐ๋ฅํ๋ค.
- Two-way communication over TLS/TCP connection
- Works with Firewalls and CDNs
- Proxy support
์ด๋ฒ์ URLSessioon๊ณผ Network.framework์์ ์น ์์ผ์ ์ด์ฉ ๊ฐ๋ฅํ๊ฒ ๋ง๋ค์๋ค!
- Foundation API for WebSocket
- Works with existing URLSession
// Create with URL
let task = URLSession.shared.webSocketTask(with: URL(string: "wss://websocket.example")!)
task.resume()
// Send a message
task.send(.string("Hello")) { error in /* Handle error */ }
// Receive a message
task.receive { result in /* Handle result */ }
- Both client and server support
- Receive partial or complete WebSocket messages
// Create parameters for WebSocket over TLS
let parameters = NWParameters.tls
let websocketOptions = NWProtocolWebSocket.Options()
parameters.defaultProtoocolStack.applicationProtocols.insert(websocketOptions, at: 0)
// Create a connection with those parameters
let websocketConnection = NWConnection(to: endppoint, using: parameters)
// Create a listener with those parameters
let websocketListener = try NWListener(using: parameters)
- WebKit
- JavaScript WebSocket
- URLSession
- URLSessionWebSocketTask
- Network.framework
- WebSocket Connection
- WebSocket Listener
๋คํธ์ํฌ๋ฅผ ์ด์ผ๊ธฐํ ๋, mobility ์ค์! Wi-Fi Assist, Multipath Transport๊ฐ ๊ฐํ iOS 13 ์๊ฐ
Cross-layer Mobility Detection, Improved Flow Recovery
- Use high-level APIs like URLSession or Network.framework
- Rethink
SCNetworkReachability
usage - Control access with
allowsExpensiveNetworkAccess = false
Responsiveness for Maps, Fewer streaming stalls in Music
- Multipath Transports for your App
multipathServiceType
URLSessionConfiguration and Network.framework
- Server-side configuration
- Linux Kernel at https://multipath-tcp.org
- Mobility should not impair your Apps
- Use high-level APIs
- Rethink interface management
- Prepare your servers and use
multipathServiceType