如何使用 macruby 进行 SCNetworkReachabilityCreateWithName
我真的不知道如何将苹果提供的示例转换为宏代码,因为地址是一个字符指针,irghhh:
SCNetworkReachabilityRef target;
SCNetworkConnectionFlags flags = 0;
Boolean ok;
target = SCNetworkReachabilityCreateWithAddress(NULL, address);
ok = SCNetworkReachabilityGetFlags(target, &flags);
CFRelease(target);
这是 Objective-C 中的示例实现:
更新:
我刚刚意识到,我可以用macruby本身很快地做到这一点,但我仍然对如何用macruby做到这一点感兴趣。
def network_available?
Socket.getaddrinfo('example.com', nil)
rescue
false
end
i really don't know how to convert the example provided by apple into macruby code, since address is a char pointer, irghhh:
SCNetworkReachabilityRef target;
SCNetworkConnectionFlags flags = 0;
Boolean ok;
target = SCNetworkReachabilityCreateWithAddress(NULL, address);
ok = SCNetworkReachabilityGetFlags(target, &flags);
CFRelease(target);
here is an example implementation in Objective-C:
Determining Internet Availability on iPhone?
UPDATE:
i just realized, that i can do it very quickly with macruby itself, but i am stil interested in how you would do this with macruby.
def network_available?
Socket.getaddrinfo('example.com', nil)
rescue
false
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该简单地获取 MacRuby NSString 实例的指针:
You should simply get the pointer of your MacRuby NSString instance: