Do not say nonsense, directly on the code.
#import <ifaddrs.h>
#import <arpa/inet.h>
-(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 En0 which are the WiFi connection on the IPhone
if ([[[NSString Stringwithutf8string:temp_addr->ifa_name] isequaltostring:@ "En0"]) {
Get NSString from C String
address = [NSString stringwithutf8string:inet_ntoa ((struct sockaddr_in *) temp_addr->ifa_addr->sin_addr)];
}
}
TEMP_ADDR = temp_addr->ifa_next;
}
}
Free memory
Freeifaddrs (interfaces);
return address;
}
iOS development--Get this device IP