Get iOS device ip address in xamarin

∥☆過路亽.° 提交于 2019-12-30 11:36:27

问题


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 ...
        }
    }
}  

}



来源:https://stackoverflow.com/questions/44904965/get-ios-device-ip-address-in-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!