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.