如何在iOS 13中支持低数据模式?

Tie*_*eme 5 networking ios swift ios13

iOS 13中引入了“低数据模式”。请参阅Apple的iOS 13概述的 “设置”部分:

低数据模式

我找不到与此有关的任何开发人员文档。

如MacRumors所说,这是第三方应用程序开发人员可以选择的吗?还是如AppleInsider所建议的那样,当未连接到Wi-Fi时,它只是暂停后台活动吗?

Ely*_*Ely 7

要确定 iOS 当前是否处于低数据模式,您可以使用网络库:

import Network // Put this on top of your class

let monitor = NWPathMonitor()

monitor.pathUpdateHandler = { path in

    if path.isConstrained {
        // Path uses an interface in Low Data Mode.
    }
    else if path.isExpensive {
        // Path uses an interface that is considered expensive, such as Cellular or a Personal Hotspot.
    }
}

monitor.start(queue: DispatchQueue.global(qos: .background))
Run Code Online (Sandbox Code Playgroud)


Cra*_*007 3

URLSession在 iOS 13 中支持LowData模式。

脚步

  • 提供高分辨率和低分辨率(低数据模式)两种不同的资源
  • 如果statusCode == 200(设置中禁用低数据模式)。
  • 如果error.networkAvailableReason == .constrained(在设置中启用低数据模式)

查看WWDC 2019 16:00 的网络进展,第 1 部分,获取演示和示例代码。您可以使用组合来使代码更简单,但这不是必需的。