0

I'm working on a project in swift 2.0. The App is for two languages chinese and english.

I'm using the SFSafariViewController to open the url. Now the problem is when i choose the english language the url load successfully. But I convert the language to chinese then the SFSafariViewController load the same url again in english.

I have sent a new parameter with url to set the language in the browser but this do not works. Any Suggestion regarding this? Thanks in advance.

Edit : Code

    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)

 }
Bilal
  • 18,478
  • 8
  • 57
  • 72
gurmeet kaur
  • 111
  • 1
  • 10

1 Answers1

0

I guess you're creating a wrong url

Please make sure that your ApiURLs.webViewPath is https://www.iceangelid.net/#/aboutus and externalURL is as below

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

If you print your externalURL then it should look like this

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

I've tested the below code and it was working fine for me, below code is for swift4 but the importing thing is the 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)
}
Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
  • Thanks for your answer.I have tried to implement the above code in my app. My control is goes into the if statement. But the browser still shows the content in the english language. – gurmeet kaur Dec 01 '17 at 09:14
  • Gurmeet I don't know what is happening at your side, can you hard code the whole url `https://www.iceangelid.net/#/aboutus?source=ios&lang=zh-CN` both in if and else statement and see what's happening – Inder Kumar Rathore Dec 01 '17 at 09:43
  • I have paste the above code and still getting the same issue. – gurmeet kaur Dec 01 '17 at 09:58