Latest 0.5
Homepage https://github.com/naptics/PlainPing
License MIT
Platforms ios 8.0, osx 10.11, requires ARC
Authors

CI Status
Version
License
Platform

A very plain ping interface to ping hostname or address, with swift 4.0. The module uses SimplePing.

To use the swift 2.2 version, select the PlainPing 0.2.2 tagged source or pod.

Usage

To run the example project, clone the repo, and run pod install in the Example directory first.

PlainPing interface

There is one class function in PlainPing, call PlainPing.ping(hostname, completionBlock).
Arguments:

  • hostName: use a name or an IP
  • completionBlock: will return the elapsed time in ms and an error, if there is one
  • withTimeout: (optional), define how long we wait for an answer in seconds, default 3s

Example:

PlainPing.ping("www.google.com", withTimeout: 1.0, completionBlock: { (timeElapsed:Double?, error:Error?) in
    if let latency = timeElapsed {
        self.pingResultLabel.text = "latency (ms): (latency)"
    }

    if let error = error {
        print("error: (error.localizedDescription)")
    }
})

Example 2:

Ping several hosts one-by-one.

var pings:[String] = []

@IBAction func pingButtonPressed(_ sender: UIButton) {
    pings = ["www.google.com", "www.naptics.ch"]
    pingNext()
}

func pingNext() {
    guard pings.count > 0 else {
        return
    }

    let ping = pings.removeFirst()
    PlainPing.ping(ping, withTimeout: 1.0, completionBlock: { (timeElapsed:Double?, error:Error?) in
        if let latency = timeElapsed {
            print("(ping) latency (ms): (latency)")
        }
        if let error = error {
            print("error: (error.localizedDescription)")
        }
        self.pingNext()
    })
}

Requirements

Minimum requirements unknown. Tested with the following:

  • xcode 9.0
  • CocoaPods 1.0

Installation

PlainPing is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "PlainPing"

Author

Jonas Schoch, [email protected]

License

PlainPing is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "PlainPing",
    "version": "0.5",
    "summary": "a very plain ping interface in swift",
    "homepage": "https://github.com/naptics/PlainPing",
    "license": "MIT",
    "authors": {
        "Jonas Schoch": "[email protected]"
    },
    "source": {
        "git": "https://github.com/naptics/PlainPing.git",
        "tag": "0.5"
    },
    "social_media_url": "https://twitter.com/naptics",
    "platforms": {
        "ios": "8.0",
        "osx": "10.11"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This