我正在使用苹果简单的ping源代码,它适用于MAC但不适用于iOS。 https://developer.apple.com/library/mac/samplecode/SimplePing/Introduction/Intro.html 下面是我写的代码
ping = [SimplePing simplePingWithHostName:@"www.google.com"];
ping.delegate = self;
[ping start];
控制台响应
2016-03-18 18:11:07.252 PinPin[383:49747] >CFHostStartInfoResolution
2016-03-18 18:11:07.256 PinPin[383:49747] <CFHostStartInfoResolution
2016-03-18 18:11:07.334 PinPin[383:49747] >HostResolveCallback
2016-03-18 18:11:07.336 PinPin[383:49747] didStartWithAddress
16-03-18 18:22:42.375 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:22:44.382 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:22:46.388 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:22:48.419 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:22:50.422 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:22:52.820 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:22:54.852 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:22:56.857 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:22:58.862 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:23:00.844 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:23:02.855 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:23:05.178 PinPin[383:49747] didReceiveUnexpectedPacket
2016-03-18 18:23:07.006 PinPin[383:49747] didReceiveUnexpectedPacket
此后没有任何事情发生,没有其他代表称为
- (void)simplePing:(SimplePing *)pinger didFailWithError:(NSError *)error;
- (void)simplePing:(SimplePing *)pinger didSendPacket:(NSData *)packet;
- (void)simplePing:(SimplePing *)pinger didFailToSendPacket:(NSData *)packet error:(NSError *)error;
- (void)simplePing:(SimplePing *)pinger didReceivePingResponsePacket:(NSData *)packet;
在readMe.txt中,苹果说
“SimplePing在Mac OS X 10.7及更高版本上运行,虽然核心代码适用于所有iOS版本,但基础方法适用于早期版本的Mac OS X(返回10.2) 。“
// UPDATE
MAC。响应
Anands-MacBook-Air:~ anand$ cd ~/Downloads/SimplePing
Anands-MacBook-Air:SimplePing anand$ build/Debug/SimplePing www.apple.com
2016-03-19 19:55:48.042 SimplePing[1149:19595] >CFHostStartInfoResolution
2016-03-19 19:55:48.045 SimplePing[1149:19595] <CFHostStartInfoResolution
2016-03-19 19:55:49.490 SimplePing[1149:19595] >HostResolveCallback
2016-03-19 19:55:49.491 SimplePing[1149:19595] pinging 23.211.220.146
2016-03-19 19:55:49.491 SimplePing[1149:19595] #0 sent
2016-03-19 19:55:49.551 SimplePing[1149:19595] #0 received
2016-03-19 19:55:50.493 SimplePing[1149:19595] #1 sent
2016-03-19 19:55:50.557 SimplePing[1149:19595] #1 received
2016-03-19 19:55:51.495 SimplePing[1149:19595] #2 sent
2016-03-19 19:55:51.553 SimplePing[1149:19595] #2 received
2016-03-19 19:55:52.493 SimplePing[1149:19595] #3 sent
2016-03-19 19:55:52.551 SimplePing[1149:19595] #3 received
2016-03-19 19:55:53.493 SimplePing[1149:19595] #4 sent
2016-03-19 19:55:53.551 SimplePing[1149:19595] #4 received
2016-03-19 19:55:54.497 SimplePing[1149:19595] #5 sent
2016-03-19 19:55:54.556 SimplePing[1149:19595] #5 received
2016-03-19 19:55:55.494 SimplePing[1149:19595] #6 sent
2016-03-19 19:55:55.550 SimplePing[1149:19595] #6 received
2016-03-19 19:55:56.492 SimplePing[1149:19595] #7 sent
2016-03-19 19:55:56.551 SimplePing[1149:19595] #7 received
2016-03-19 19:55:57.498 SimplePing[1149:19595] #8 sent
2016-03-19 19:55:57.562 SimplePing[1149:19595] #8 received
2016-03-19 19:55:58.494 SimplePing[1149:19595] #9 sent
2016-03-19 19:55:58.552 SimplePing[1149:19595] #9 received
答案 0 :(得分:1)
尝试将此添加到您的didStartWithAddress
:
- (void)simplePing:(SimplePing *)pinger didStartWithAddress:(NSData *)address
{
[pinger sendPingWithData:nil];
}