NetworkReachabilityManager

open class NetworkReachabilityManager : @unchecked Sendable

网络可达性管理器

Alamofire

  • 网络可达性状态枚举

    See more

    Declaration

    Swift

    public enum NetworkReachabilityStatus : Equatable, Sendable
  • 网络可达性监听句柄

    Declaration

    Swift

    public typealias Listener = @Sendable (NetworkReachabilityStatus) -> Void
  • 默认网络可达性管理器

    Declaration

    Swift

    public static let shared: NetworkReachabilityManager

Accessor

  • 当前是否可访问网络

    Declaration

    Swift

    open var isReachable: Bool { get }
  • 当前是否通过蜂窝网络访问

    Declaration

    Swift

    open var isReachableOnCellular: Bool { get }
  • 当前是否通过以太网或WiFi网络访问

    Declaration

    Swift

    open var isReachableOnEthernetOrWiFi: Bool { get }
  • 可达性更新时回调队列

    Declaration

    Swift

    public let reachabilityQueue: DispatchQueue
  • 当前可访问类型标记

    Declaration

    Swift

    open var flags: SCNetworkReachabilityFlags? { get }
  • 当前网络可达性状态

    Declaration

    Swift

    open var status: NetworkReachabilityStatus { get }

Lifecycle

  • 指定host初始化

    Declaration

    Swift

    public convenience init(host: String)
  • 使用默认地址0.0.0.0初始化

    Declaration

    Swift

    public convenience init()

Public

  • 是否正在监听中

    Declaration

    Swift

    open var isListening: Bool { get }
  • 开始监听网络状态,自动停止之前已有的监听

    Declaration

    Swift

    @discardableResult
    open func startListening(onQueue queue: DispatchQueue = .main,
                             onUpdatePerforming listener: @escaping Listener) -> Bool

    Parameters

    queue

    监听句柄回调队列,默认main

    listener

    监听句柄

    Return Value

    true if listening was started successfully, false otherwise.

  • 停止监听

    Declaration

    Swift

    open func stopListening()