iOS端的一个ping网络工具,修复了之前不能并发Ping的bug和不能在子线程中发起的bug
此次版本还加入了pod支持,可以通过pod进行集成
直接将 PPSPing 下的源码拷贝到工程目录中,在使用的时候直接引入 PPSPingServices 文件即可
pod 'PPSPing', '~> 0.1.0'
ping的结果与电脑端的ping方式相似,数据格式相同
@interface PPSAppDelegate()
@property (nonatomic, strong) PPSPingServices *service;
@end
@implementation PPSAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.service = [PPSPingServices serviceWithAddress:@"www.163.com"];
[self.service startWithCallbackHandler:^(PPSPingSummary *pingItem, NSArray *pingItems) {
NSLog(@"%@",pingItem);
}];
return YES;
}
@end
注意:在使用时,需要service存在强引用,否则不能收到回调结果
@interface PPSAppDelegate()
//@property (nonatomic, strong) PPSPingServices *service;
@end
@implementation PPSAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
PPSPingServices *service = [PPSPingServices serviceWithAddress:@"www.163.com"];
[service startWithCallbackHandler:^(PPSPingSummary *pingItem, NSArray *pingItems) {
NSLog(@"%@",pingItem);
}];
return YES;
}
@end
上面这种使用方式,将得不到回调结果,在块执行完成后,service 已经销毁
看一下效果图:
后面如果有时间,会继续完善