Friday, 24 August 2018

iOS: How to get the IP Address from Host name Objective C

- (NSString *)getIPAddress {
Boolean result;
CFHostRef hostRef;
CFArrayRef addresses;
NSString *hostname = @"www.google.com"; /*change to required host name */
NSString *ipAddress = @"";
hostRef = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)hostname);
if (hostRef) {
result = CFHostStartInfoResolution(hostRef, kCFHostAddresses, NULL);
if (result == TRUE) {
addresses = CFHostGetAddressing(hostRef, &result);
}
}
if (result == TRUE) {
CFIndex index = 0;
CFDataRef ref = (CFDataRef) CFArrayGetValueAtIndex(addresses, index);
struct sockaddr_in* remoteAddr;
char *ip_address;
remoteAddr = (struct sockaddr_in*) CFDataGetBytePtr(ref);
if (remoteAddr != NULL) {
ip_address = inet_ntoa(remoteAddr->sin_addr);
}
ipAddress = [NSString stringWithCString:ip_address encoding:NSUTF8StringEncoding];
}
return ipAddress;
}

Setting Up Multiple App Targets in Xcode from a Single Codebase

 To create two different apps (like "Light" and "Regular") from the same codebase in Xcode, you can follow these steps b...