Introduction
Welcome to the documentation for Swiftping, a powerful Swift library for implementing ping functionality in your iOS applications. Swiftping allows you to easily check the availability and response time of remote servers or network devices using the ICMP ping protocol.
Installation
Requirements
- iOS 11.0 or later
- Swift 5.0 or later
Installation via CocoaPods
To integrate Swiftping into your Xcode project using CocoaPods, add the following line to your `Podfile`:
pod 'Swiftping'
Then run the following command:
$ pod install
Installation via Swift Package Manager
Alternatively, you can use Swift Package Manager to add Swiftping as a dependency. In Xcode, go to `File` > `Swift Packages` > `Add Package Dependency` and enter the repository URL:
https://github.com/swiftping/swiftping.git
Usage
Importing Swiftping
You’ll need to import the Swiftping module in the files where you want to use the library:
import Swiftping
Pinging a Server
To ping a server or network device using Swiftping, create an instance of the `Ping` class and provide the host (IP address or domain name) as a parameter:
let ping = Ping(host: "example.com")
Next, you can set optional properties such as the ping timeout and the number of ping packets to send:
ping.timeout = 1.0 // seconds
ping.count = 5
To start the ping process, call the `start()` method:
ping.start()
You can handle the ping results using the `PingDelegate` protocol. Implement the required delegate methods to receive the ping results:
class MyPingDelegate: PingDelegate {
func didStartPing() {
// Ping process started
}
func didSendPingPacket() {
// Ping packet sent successfully
}
func didReceivePingResponsePacket() {
// Received ping response packet
}
func didReceivePingError(error: Error) {
// Error occurred during the ping process
}
func didFinishPing(successfulPings: Int, failedPings: Int) {
// Ping process completed
}
}
Set the delegate object for the Ping instance to start receiving the ping events:
ping.delegate = MyPingDelegate()
Support
If you encounter any issues or have any questions, you can find further support and contact information on the Swiftping GitHub repository.
License
Swiftping is available under the MIT license. See the LICENSE file for more information.