Xamarin.iOS Ping 结果 System.InvalidOperationException

Xamarin.iOS Ping resulting in System.InvalidOperationException

在我的代码中,我尝试执行以下操作:

Ping ping = new Ping();
var reply = ping.Send(ipAddress);

然而这总是抛出 System.InvalidOperationException:

"Operation is not valid due to the current state of the object."

我在 iOS9.1 台设备上 运行。

您不想使用 Mono Ping 例程,因为它在 iOS 上不起作用。 Xamarin 已将 Apple 的 SimplePing 示例代码包装成 package/nuget (Xamarin.SimplePing).

var pinger = new SimplePing("www.apple.com");

pinger.Started += (sender, e) => {
    var endpoint = e.EndPoint;
    pinger.SendPing(null);
};

pinger.ResponseRecieved += (sender, e) => {
    var seq = e.SequenceNumber;
    var packet = e.Packet;
};

pinger.Start();

回复:https://github.com/xamarin/XamarinComponents/tree/master/iOS/SimplePing

回复:https://developer.apple.com/library/content/samplecode/SimplePing