0

how to convert Nsurl Domain to my country domain

Example :

NSURL *url = [NSURL URLWithString:@"http://www.google.com"];

How can get some thing like http://www.google.com.eg

it can detect my zone and change it with my domain zone, if website support multi zones domain.

Mohamed Helmy
  • 821
  • 1
  • 9
  • 20

1 Answers1

0

If there isn't a path in the url just append .eg to the end of the string.

NSString *newCountryString = [[url absoluteString] stringByAppendingString:@".eg"];

NSURL *newCountryUrl = [NSURL URLWithString:newCountryString];

If the url has a path do this:

NSString *host = [url host];
NSString *domain = [[host componentsSeparatedByString:@"."] lastObject];
NSString *newCountryString = [[url absoluteString] stringByReplacingOccurrencesOfString:domain withString:[domain stringByAppendingString:@".eg"]];
NSURL *newCountryUrl = [NSURL URLWithString:newCountryString];
lopes710
  • 315
  • 1
  • 3
  • 19
  • i don't want to add "eg" specific i want to add any zone like "uk,..." – Mohamed Helmy Aug 01 '16 at 13:32
  • eg was just an example. If you want to get location by language settings use: NSString *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode]; if you want by physical location check this post, http://stackoverflow.com/questions/8534496/get-device-location-only-country-in-ios – lopes710 Aug 02 '16 at 14:02