0

我正在尝试在 iOS 设备上初始化 JmDNS,使用以下行获取地址:

InetAddress adr = InetAddress.getLocalHost();

它在 iphone 模拟器中运行良好,但是在物理 iOS 设备上进行测试时,这会导致 UnknownHostException,并带有堆栈跟踪:

java.net.UnknownHostException: Unable to resolve host "#{name of iphone}": nodename nor servname provided, or not known
at libcore.io.GaiException.rethrowAsUnknownHostException(GaiException.java)
at java.net.InetAddress.lookupHostByName(InetAddress.java)
at java.net.InetAddress.getLocalHost(InetAddress.java)
at com.glassknuckle.ThiefTown.Networking.ThiefClient$NETWORK_TASK.run(ThiefClient.java)
at java.lang.Thread.run(Thread.java)
Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NONAME (nodename nor servname provided, or not known)
at libcore.io.Posix.getaddrinfo(Native Method)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java)
... 4 more

我读过建议将“127.0.0.1”作为地址传递,但是当其他设备试图通过该 IP 连接到它时,这不起作用。我不确定从这里做什么——我肯定需要获取本地 IP 地址,但我不知道如何获取它。这似乎与 roboVM 有关,但我不完全确定。也许有人可以对此有所了解?

4

1 回答 1

0

我自己想通了。显然,iOS 阻止您通过 getLocalHost 获取本地 IP 地址。我不得不使用 RoboVM 桥插入一个 Objective-C 脚本来做到这一点:http ://blog.robovm.org/2013/08/support-for-objective-c-blocks.html

于 2014-07-11T03:30:02.137 回答