IMNetworkReachability 0.2.1

IMNetworkReachability 0.2.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年12月
SPM支持SPM

Ivan Magda维护。



IMNetworkReachability是一个可用性框架。它旨在帮助您与网络活动事件进行接口交互。它允许您同步和异步地监控网络状态。

示例

同步

let reachability = IMNetworkReachability("www.google.com")

switch reachability.isReachable() {
  case .reachable:
    print("Reachable")
  case .offline:
    print("Offline")
  case .error(let error):
    print("Failed to check for a network reachability, error: \(error)")
}

闭包

// Declare this property where it won't go out of scope relative to your listener
let reachability = IMNetworkReachability("www.google.com")

reachability.startListening { (result) in
// this is called on a main thread
  switch result {
    case .reachable:
      print("Reachable")
    case .offline:
      print("Offline")
    case .error(let error):
      print("Failed to check for a network reachability, error: \(error)")
  }
}

用于停止通知

reachability.stopListening()

此外,别忘了在macOS上启用网络访问

安装

IMNetworkReachability支持多种方法在项目中安装库。

Podfile

要使用CocoaPods将IMNetworkReachability集成到Xcode项目中,请在Podfile中指定它

source 'https://github.com/CocoaPods/Specs.git'

target 'iOS' do
  platform :ios, '8.0'
  use_frameworks!

  pod 'IMNetworkReachability', '~> 0.1'

end

target 'macOS' do
  platform :osx, '10.9'
  use_frameworks!

  pod 'IMNetworkReachability', '~> 0.1'

end

target 'tvOS' do
  platform :tvos, '9.0'
  use_frameworks!

  pod 'IMNetworkReachability', '~> 0.1'

end

然后,运行以下命令

$ pod install

作者

我是Ivan Magda。电子邮件:[email protected]。Twitter:@magda_ivan

许可证

此项目是基于MIT许可证的开源软件。

有关更多信息,请参阅LICENSE文件。