gpt4 book ai didi

ios - 为什么 Apple 简单 ping 在 iOS 上不起作用?

转载 作者:行者123 更新时间:2023-11-29 12:03:17 31 4
gpt4 key购买 nike

我正在使用适用于 MAC 但不适用于 iOS 的苹果简单 ping 源代码。 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) ”

//更新

麦克。回应

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

最佳答案

尝试将此添加到您的 didStartWithAddress:

- (void)simplePing:(SimplePing *)pinger didStartWithAddress:(NSData *)address 
{
[pinger sendPingWithData:nil];
}

关于ios - 为什么 Apple 简单 ping 在 iOS 上不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36084912/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com