IOS gets mobile IP address code _ios

Source: Internet
Author: User
Tags get ip

This example for you to share the iOS access to mobile phone IP address of the specific code for your reference, the specific content as follows

#import <ifaddrs.h> #import <arpa/inet.h>/Get IP address-(NSString *) getipaddress {nsstring *address
  = @ "Error";
  struct Ifaddrs *interfaces = NULL;
  struct Ifaddrs *temp_addr = NULL;
  int success = 0;
  Retrieve the current Interfaces-returns 0 on success success = Getifaddrs (&interfaces);
    if (success = = 0) {//Loop through linked list of interfaces temp_addr = interfaces; while (temp_addr!= NULL) {if (temp_addr->ifa_addr->sa_family = = af_inet) {//Check if interface is en 0 which is the "WiFi" connection on the IPhone if ([[NSString Stringwithutf8string:temp_addr->ifa_name] Isequaltos tring:@ "En0"]) {//Get nsstring from C String address = [NSString Stringwithutf8string:inet_ntoa ((St
        Ruct sockaddr_in *) temp_addr->ifa_addr)->sin_addr)];
    }} temp_addr = temp_addr->ifa_next;
  }//Free memory Freeifaddrs (interfaces);
return address;

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.