SimplePing for MonoTouch现在可以在这里找到。
https://github.com/theonlylawislove/MonoTouch.SimplePing
简单的附加这个混帐回购作为一个子模块到您的项目,然后选择“添加现有项目”,并增加了“MonoTouch.SimplePing”到您的项目。有一个小的帮助器类可以使“SimplePingHelper”的“MonoTouch.SimplePing.Test”项目变得更容易一些。
然后使用下面的代码。
SimplePingHelper.Ping (
"192.168.5.77",
1000,
() => {
NSThread.MainThread.BeginInvokeOnMainThread (new NSAction (() => {
var alertView = new UIAlertView ("Response", "Success", null, null, new string[] { "Ok" });
alertView.Show();
}));
},
() => {
NSThread.MainThread.BeginInvokeOnMainThread (new NSAction (() => {
var alertView = new UIAlertView ("Response", "Failure", null, null, new string[] { "Ok" });
alertView.Show();
}));
});
该解决方案适用于模拟器和我测试的每个设备。
不要使用任何在互联网上发现的“RawSocket”黑客攻击。它充斥着异步代码的错误,并且它在某些设备上工作而不是其他设备上的问题。把我的头发拉出来后,我想我会移植SimplePing项目,因为我发现它确实有效。
享受!
好奇:你有没有想过在设备上使用JIT而不是AOT进行调试版本?它不会让每个人都过得更轻松吗? – Krumelur