Get iOS device ip address in xamarin

前端 未结 1 1121
萌比男神i
萌比男神i 2021-01-16 02:42

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 solu

相关标签:
1条回答
  • 2021-01-16 03:05

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

    }

    0 讨论(0)
提交回复
热议问题