简体   繁体   English

如何在iOS上检测设备IP地址变化?

[英]How to detect device IP address change on iOS?

Is this even possible? 这甚至可能吗? I couldn't find code on how to do it. 我找不到如何做的代码。 When not on Wi-Fi, the device IP keeps changing, & I need to keep track of that. 当不在Wi-Fi上时,设备IP不断变化,我需要跟踪它。

You can use Rechability and schedule some timer to check whether any change occurred. 您可以使用Rechability并安排一些计时器来检查是否发生了任何更改。 It will looks like that and this . 它会看起来像那个这个

For retrieving IP address you can try this code . 要检索IP地址,您可以尝试使用此代码

If possible test with a real device not a simulator as it probably will not be working properly on the simulator (once I tested sth similar and it failed on the simulator while worked perfectly fine on the real devices). 如果可能的话,用真实的设备测试而不是模拟器,因为它可能无法在模拟器上正常工作(一旦我测试了类似的,它在模拟器上失败,而在真实设备上工作得非常好)。

不确定是否可以直接使用,但使用Reachability来捕获每个网络重新连接,每次都可以获得新的ip。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM