【问题标题】:convert Nsurl Domain to my country domain将 Nsurl 域转换为我的国家域
【发布时间】:2016-12-06 13:39:32
【问题描述】:

如何将 Nsurl 域转换为我的国家域

例子:

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

如何获得类似http://www.google.com.eg

如果网站支持多区域域,它可以检测我的区域并使用我的域区域更改它。

【问题讨论】:

    标签: ios objective-c swift xcode


    【解决方案1】:

    如果 url 中没有路径,只需将 .eg 附加到字符串的末尾即可。

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

    如果网址有路径,请执行以下操作:

    NSString *host = [url host];
    NSString *domain = [[host componentsSeparatedByString:@"."] lastObject];
    NSString *newCountryString = [[url absoluteString] stringByReplacingOccurrencesOfString:domain withString:[domain stringByAppendingString:@".eg"]];
    NSURL *newCountryUrl = [NSURL URLWithString:newCountryString];
    

    【讨论】:

    • 我不想添加“eg”,具体我想添加任何区域,例如“uk,...”
    • 例如只是一个例子。如果您想通过语言设置获取位置,请使用: NSString *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];如果您想按实际位置查看此帖子,stackoverflow.com/questions/8534496/…
    猜你喜欢
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多