salbahra / cordova-plugin-networkinterface

Provide a method for Cordova applications to retrieve the device IP Address.
http://albahra.com/projects
72 stars 51 forks source link

getWiFiIPAddress sometimes returns 0.0.0.0 on iOS (solution included) #46

Closed qpwr closed 3 years ago

qpwr commented 4 years ago

This plugin doesn't seem to be maintained anymore, but in case anyone is using it and experiencing the issue mentioned in the title: This is because the plugin just goes through all en0 interfaces (which is wifi) and uses always the last one. It seems that there is sometimes more than one en0, but some of them with IP 0.0.0.0 (probably non-active ones). If one of the 0.0.0.0 happen to be looped through after the actual active en0 interface, the returned IP will be 0.0.0.0.

To patch this, you have to make some changes to CDVNetworkInterface.m, line 22 (within the getInterfaceiIP function):

Search for

if([name isEqualToString:interfaceName]

and change it to

if([name isEqualToString:interfaceName] && ![addr isEqualToString:@"0.0.0.0"])

Hope someone finds this helpful.

salbahra commented 3 years ago

Just added this change, thank you for this issue and solution!

Bastien3093 commented 3 years ago

Hello ! Your latest version generates build errors on iOS

cordova-plugin-networkinterface/CDVNetworkInterface.m expected identifier or '(' and cordova-plugin-networkinterface/CDVNetworkInterface.m extraneous closing brace ('}')

salbahra commented 3 years ago

Ah darn must have been a bad merge, let me take a look at this today.

Thank you for the heads up! Samer

On Wed, Oct 6, 2021 at 8:03 AM Bastien3093 @.***> wrote:

Hello ! Your latest version generates build errors on iOS

cordova-plugin-networkinterface/CDVNetworkInterface.m expected identifier or '(' and cordova-plugin-networkinterface/CDVNetworkInterface.m extraneous closing brace ('}')

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/salbahra/cordova-plugin-networkinterface/issues/46#issuecomment-936453789, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7W6FXZ2KS73VUW55HP3OTUFRQMRANCNFSM4SQKU3CA .

salbahra commented 3 years ago

Should be fixed in 2.2.0! Thank you very much!

Bastien3093 commented 3 years ago

Amazing ! Thanks to you :)