易于使用的 iOS ICMP ping - 只需创建一个 CDZPinger,您的代理每秒钟都会收到带有平均 ping 时间的回调。
将依赖项添加到您的 Podfile
platform :ios
pod 'CDZPinger'
...
运行 pod install
以安装依赖项。
#import "CDZPinger.h"
并
CDZPinger *pinger = [[CDZPinger alloc] initWithHost:@"google.com"];
// keep a strong reference to pinger, maybe in a property somewhere
pinger.delegate = self;
// (assuming self is your CDZPingerDelegate)
在您的代理中
#pragma mark CDZPingerDelegate
- (void)pinger:(CDZPinger *)pinger didUpdateWithAverageSeconds:(NSTimeInterval)seconds
{
NSLog([NSString stringWithFormat:@"Received ping; average time %.f ms", seconds*1000]);
}
CDZPinger
需要 iOS 5.x+。它可能在 iOS 4 上运行,但我没有测试过。
还有可能在 OS X 上运行,但同样,我也没有在那里测试过。
MIT 许可证。有关详细信息,请参阅 LICENSE。
Chris Dzombak,代码来自 Apple 的示例代码。