Search code examples
iosswiftuiwebviewurlrequest

link is not opening in uiwebview


I have link as below,

https://payood.test/loofpay/XUYZGlobal/WebForms/checkoutservice%20.aspx?paymentchannel=ddd&isysid=37268474138868&amount=25&description=Transaction From XXX&description2=dsdsd&tunnel=&original=ZXz4kfH9fiVIZ1jWBaGjww3hgwX84CGAahlCcsKWXvs%3d&responseUrl=http://localhost:55766/dsss/Response.aspx&hash=BE0481E5F9AA1C9F5B26A8E93A6ACAAD5888EDE9

When I try to open, its crashing saying below error.

fatal error: unexpectedly found nil while unwrapping an Optional value

Below is the code I am using

link = above link....
webView.loadRequest(URLRequest(url: URL(string: link)!))

Note:

If I use simple link as http://www.google.com, it works.


Solution

  • I found that url is already encoded but API have issues that they are sending spaces in url.

    So I replace spaces with %20

    link = link.replacingOccurrences(of: " ", with: "%20")
    

    This way all is working fine now.