hi can you please tell me how to access iOS device ip address using xamarin. we are building iOS app in which we want to show device local ip address. I used many other solutions but they didnt work for me.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I found a post about it here: https://forums.xamarin.com/discussion/348/acquire-device-ip-addresses-monotouch-since-ios6-0
it goes as follow: Try using System.Net.NetworkInformation.NetworkInterface:
foreach (var netInterface in NetworkInterface.GetAllNetworkInterfaces()) {
if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet) {
foreach (var addrInfo in netInterface.GetIPProperties().UnicastAddresses) {
if (addrInfo.Address.AddressFamily == AddressFamily.InterNetwork) {
var ipAddress = addrInfo.Address;
// use ipAddress as needed ...
}
}
}
}