SFSafariViewController语言未更新

时间:2017-12-01 07:29:45

标签: ios swift sfsafariviewcontroller

我正在使用swift 2.0开展项目。该应用程序适用于中英文两种语言。

我正在使用SFSafariViewController打开网址。现在问题是当我选择英语时,url加载成功。但我将语言转换为中文,然后SFSafariViewController再次以英文加载相同的URL。

我已经使用url发送了一个新参数来设置浏览器中的语言,但这不起作用。对此有何建议? 提前谢谢。

编辑:代码

    let language = (Localize.currentLanguage() != "zh-Hans" ? "en" : "zh")
 if language == "zh"{
  let externalURL = ApiURLs.webViewPath + "/?source=ios&lang=zh-CN"

  let safariVC = SFSafariViewController(URL: NSURL(string: externalURL)!)

  self.presentViewController(safariVC, animated: true, completion: nil)

 }
  else
{
   let externalURL = ApiURLs.webViewPath + "/?source=ios&lang=en-US"

   let safariVC = SFSafariViewController(URL: NSURL(string: externalURL)!)

   self.presentViewController(safariVC, animated: true, completion: nil)

 }

1 个答案:

答案 0 :(得分:0)

我猜你正在创建一个错误的网址

请确保您的ApiURLs.webViewPath https://www.iceangelid.net/#/aboutusexternalURL如下

let externalURL = ApiURLs.webViewPath + "?source=ios&lang=zh-CN"

如果您打印externalURL,那么它应该是这样的

https://www.iceangelid.net/#/aboutus?source=ios&lang=zh-CN

我已经测试了下面的代码并且它对我来说工作正常,下面的代码是针对swift4但是导入的东西是url

if language == "zh" {
  let externalURL = "https://www.iceangelid.net/#/aboutus?source=ios&lang=zh-CN"
  let safariVC = SFSafariViewController(url: URL(string: externalURL)! as URL)
  self.present(safariVC, animated: true, completion: nil)
}
else {
  let externalURL = "https://www.iceangelid.net/#/aboutus?source=ios&lang=en-US"
  let safariVC = SFSafariViewController(url: URL(string: externalURL)! as URL)
  self.present(safariVC, animated: true, completion: nil)
}