我正在做一个swift 2.0的项目。该应用程序是两种语言的中文和英文。
我正在使用SFSafariViewController打开url。现在的问题是,当我选择英语时,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)
}发布于 2017-12-01 17:04:32
我猜你创建了一个错误的url
请确保您的ApiURLs.webViewPath为https://www.iceangelid.net/#/aboutus,externalURL如下所示
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)
}https://stackoverflow.com/questions/47588574
复制相似问题